2021-10-17 20:38:46 +02:00
|
|
|
package com.simplemobiletools.voicerecorder.activities
|
|
|
|
|
|
|
|
import android.content.Intent
|
2023-05-07 18:43:22 +02:00
|
|
|
import com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
|
2023-07-17 14:48:58 +02:00
|
|
|
import com.simplemobiletools.commons.extensions.openNotificationSettings
|
2021-10-17 20:38:46 +02:00
|
|
|
import com.simplemobiletools.voicerecorder.services.RecorderService
|
|
|
|
|
|
|
|
class BackgroundRecordActivity : SimpleActivity() {
|
|
|
|
companion object {
|
2021-10-18 19:37:49 +02:00
|
|
|
const val RECORD_INTENT_ACTION = "RECORD_ACTION"
|
2021-10-17 20:38:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
if (intent.action == RECORD_INTENT_ACTION) {
|
2022-09-11 18:59:39 +02:00
|
|
|
handleNotificationPermission { granted ->
|
|
|
|
if (granted) {
|
2022-08-29 10:48:19 +02:00
|
|
|
Intent(this@BackgroundRecordActivity, RecorderService::class.java).apply {
|
|
|
|
try {
|
|
|
|
if (RecorderService.isRunning) {
|
|
|
|
stopService(this)
|
|
|
|
} else {
|
|
|
|
startService(this)
|
|
|
|
}
|
|
|
|
} catch (ignored: Exception) {
|
|
|
|
}
|
2021-10-17 20:38:46 +02:00
|
|
|
}
|
2022-08-29 10:48:19 +02:00
|
|
|
} else {
|
2023-08-04 08:43:55 +02:00
|
|
|
PermissionRequiredDialog(this, com.simplemobiletools.commons.R.string.allow_notifications_voice_recorder, { openNotificationSettings() })
|
2021-10-17 20:38:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
moveTaskToBack(true)
|
|
|
|
finish()
|
|
|
|
}
|
|
|
|
}
|