chore: 명언/운세 API 수집 비활성화 및 애플뮤직 자동 실행 제거
- ForeGroundService.kt:
* QuoteFetchWorker.doWork() 즉시 Result.success() 반환으로 zenquotes/korean-advice API 호출 비활성화
* refreshFeeds()에서 QuoteFetchWork 주기적 등록 제거 및 workManager.cancelUniqueWork("QuoteFetchWork") 호출로 기존 예약 작업 취소
* launchAppleMusic() 메서드 및 bluetoothreceiver 내 애플뮤직 자동 실행 관련 주석 코드 제거
- 검증: ./gradlew :app:compileDebugKotlin 빌드 성공 확인 (16s, 133 actionable tasks)
This commit is contained in:
@@ -87,13 +87,8 @@ data class KorAdviceResponse(val author: String, val message: String)
|
||||
class QuoteFetchWorker(private val context: Context, params: WorkerParameters) : CoroutineWorker(context, params) {
|
||||
|
||||
override suspend fun doWork(): Result {
|
||||
return try {
|
||||
fetchAndSaveQuotes()
|
||||
Result.success()
|
||||
} catch (e: Exception) {
|
||||
Blog.LOGE("QuoteFetchWorker Failed", e)
|
||||
Result.retry() // 실패 시 재시도
|
||||
}
|
||||
// 명언/운세 API 수집 비활성화
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
private suspend fun fetchAndSaveQuotes() {
|
||||
@@ -739,22 +734,8 @@ class ForeGroundService : Service() {
|
||||
workManager.enqueueUniquePeriodicWork("AggregatedSystemWork", ExistingPeriodicWorkPolicy.KEEP, systemRequest)
|
||||
workManager.enqueueUniquePeriodicWork("AggregatedNewsWork", ExistingPeriodicWorkPolicy.KEEP, newsRequest)
|
||||
|
||||
|
||||
val quoteRequest = PeriodicWorkRequestBuilder<QuoteFetchWorker>(
|
||||
2, TimeUnit.HOURS // 1시간 간격 설정
|
||||
)
|
||||
.setConstraints(
|
||||
Constraints.Builder()
|
||||
.setRequiredNetworkType(NetworkType.CONNECTED) // 네트워크가 연결된 상태에서만 실행
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
|
||||
workManager.enqueueUniquePeriodicWork(
|
||||
"QuoteFetchWork",
|
||||
ExistingPeriodicWorkPolicy.KEEP,
|
||||
quoteRequest
|
||||
)
|
||||
// 명언/운세 API 수집 비활성화: 기존 예약 작업 취소
|
||||
workManager.cancelUniqueWork("QuoteFetchWork")
|
||||
|
||||
}
|
||||
|
||||
@@ -866,60 +847,12 @@ class ForeGroundService : Service() {
|
||||
val majorClass = device?.bluetoothClass?.majorDeviceClass
|
||||
if (majorClass == BluetoothClass.Device.Major.AUDIO_VIDEO) {
|
||||
Blog.LOGE("Audio Bluetooth Connected: ${device?.name ?: "Unknown"}")
|
||||
// if ("BUMz pod".equals(device?.name)) {
|
||||
// launchAppleMusic(context)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchAppleMusic(context: Context) {
|
||||
try {
|
||||
val appleMusicPackage = "com.apple.android.music"
|
||||
val launchIntent = context.packageManager.getLaunchIntentForPackage(appleMusicPackage)
|
||||
|
||||
if (launchIntent != null) {
|
||||
// 서비스(백그라운드)에서 화면을 띄우려면 NEW_TASK 플래그가 필수입니다.
|
||||
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
|
||||
context.startActivity(launchIntent)
|
||||
Blog.LOGE("애플뮤직 자동 실행 완료")
|
||||
serviceScope.launch(Dispatchers.Main) {
|
||||
delay(1500) // 1.5초 대기 (기기 속도에 따라 1000~2000 사이로 조절 가능)
|
||||
|
||||
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
val eventTime = SystemClock.uptimeMillis()
|
||||
|
||||
// 재생 버튼 누름 (ACTION_DOWN)
|
||||
val downEvent = KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY, 0)
|
||||
audioManager.dispatchMediaKeyEvent(downEvent)
|
||||
|
||||
// 재생 버튼 뗌 (ACTION_UP)
|
||||
val upEvent = KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY, 0)
|
||||
audioManager.dispatchMediaKeyEvent(upEvent)
|
||||
|
||||
Blog.LOGE("애플뮤직 미디어 재생(Play) 명령 전송 완료 🎵")
|
||||
delay(300) // 시스템이 재생 명령을 처리할 수 있도록 아주 잠깐 대기
|
||||
|
||||
// 💡 3. 홈 화면(런처)으로 즉시 강제 복귀
|
||||
val homeIntent = Intent(Intent.ACTION_MAIN).apply {
|
||||
addCategory(Intent.CATEGORY_HOME)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
context.startActivity(homeIntent)
|
||||
Blog.LOGE("런처(홈) 화면으로 복귀 완료")
|
||||
}
|
||||
|
||||
} else {
|
||||
Blog.LOGE("애플뮤직 앱이 기기에 설치되어 있지 않습니다.")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Blog.LOGE("애플뮤직 실행 중 오류 발생: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
try {
|
||||
unregisterReceiver(bluetoothreceiver)
|
||||
|
||||
Reference in New Issue
Block a user