mirror of
https://github.com/SimpleMobileTools/Simple-Voice-Recorder.git
synced 2025-06-05 21:59:31 +02:00
stop amplitude updates when app is in background
This commit is contained in:
@ -69,6 +69,7 @@
|
|||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.simplemobiletools.voicerecorder.action.GET_RECORDER_INFO" />
|
<action android:name="com.simplemobiletools.voicerecorder.action.GET_RECORDER_INFO" />
|
||||||
|
<action android:name="com.simplemobiletools.voicerecorder.action.STOP_AMPLITUDE_UPDATE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import com.simplemobiletools.commons.models.FAQItem
|
|||||||
import com.simplemobiletools.voicerecorder.BuildConfig
|
import com.simplemobiletools.voicerecorder.BuildConfig
|
||||||
import com.simplemobiletools.voicerecorder.R
|
import com.simplemobiletools.voicerecorder.R
|
||||||
import com.simplemobiletools.voicerecorder.helpers.GET_RECORDER_INFO
|
import com.simplemobiletools.voicerecorder.helpers.GET_RECORDER_INFO
|
||||||
|
import com.simplemobiletools.voicerecorder.helpers.STOP_AMPLITUDE_UPDATE
|
||||||
import com.simplemobiletools.voicerecorder.models.Events
|
import com.simplemobiletools.voicerecorder.models.Events
|
||||||
import com.simplemobiletools.voicerecorder.services.RecorderService
|
import com.simplemobiletools.voicerecorder.services.RecorderService
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
@ -56,6 +57,11 @@ class MainActivity : SimpleActivity() {
|
|||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
bus?.unregister(this)
|
bus?.unregister(this)
|
||||||
|
|
||||||
|
Intent(this@MainActivity, RecorderService::class.java).apply {
|
||||||
|
action = STOP_AMPLITUDE_UPDATE
|
||||||
|
startService(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
@ -4,3 +4,4 @@ const val RECORDER_RUNNING_NOTIF_ID = 10000
|
|||||||
|
|
||||||
private const val PATH = "com.simplemobiletools.voicerecorder.action."
|
private const val PATH = "com.simplemobiletools.voicerecorder.action."
|
||||||
const val GET_RECORDER_INFO = PATH + "GET_RECORDER_INFO"
|
const val GET_RECORDER_INFO = PATH + "GET_RECORDER_INFO"
|
||||||
|
const val STOP_AMPLITUDE_UPDATE = PATH + "STOP_AMPLITUDE_UPDATE"
|
||||||
|
@ -21,6 +21,7 @@ import com.simplemobiletools.voicerecorder.R
|
|||||||
import com.simplemobiletools.voicerecorder.activities.SplashActivity
|
import com.simplemobiletools.voicerecorder.activities.SplashActivity
|
||||||
import com.simplemobiletools.voicerecorder.helpers.GET_RECORDER_INFO
|
import com.simplemobiletools.voicerecorder.helpers.GET_RECORDER_INFO
|
||||||
import com.simplemobiletools.voicerecorder.helpers.RECORDER_RUNNING_NOTIF_ID
|
import com.simplemobiletools.voicerecorder.helpers.RECORDER_RUNNING_NOTIF_ID
|
||||||
|
import com.simplemobiletools.voicerecorder.helpers.STOP_AMPLITUDE_UPDATE
|
||||||
import com.simplemobiletools.voicerecorder.models.Events
|
import com.simplemobiletools.voicerecorder.models.Events
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -44,6 +45,7 @@ class RecorderService : Service() {
|
|||||||
|
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
GET_RECORDER_INFO -> broadcastRecorderInfo()
|
GET_RECORDER_INFO -> broadcastRecorderInfo()
|
||||||
|
STOP_AMPLITUDE_UPDATE -> amplitudeTimer.cancel()
|
||||||
else -> startRecording()
|
else -> startRecording()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,8 +87,7 @@ class RecorderService : Service() {
|
|||||||
durationTimer = Timer()
|
durationTimer = Timer()
|
||||||
durationTimer.scheduleAtFixedRate(getDurationUpdateTask(), 1000, 1000)
|
durationTimer.scheduleAtFixedRate(getDurationUpdateTask(), 1000, 1000)
|
||||||
|
|
||||||
amplitudeTimer = Timer()
|
startAmplitudeUpdates()
|
||||||
amplitudeTimer.scheduleAtFixedRate(getAmplitudeUpdateTask(), 0, AMPLITUDE_UPDATE_MS)
|
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
stopRecording()
|
stopRecording()
|
||||||
@ -117,6 +118,16 @@ class RecorderService : Service() {
|
|||||||
private fun broadcastRecorderInfo() {
|
private fun broadcastRecorderInfo() {
|
||||||
broadcastDuration()
|
broadcastDuration()
|
||||||
broadcastStatus()
|
broadcastStatus()
|
||||||
|
|
||||||
|
if (isRecording) {
|
||||||
|
startAmplitudeUpdates()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startAmplitudeUpdates() {
|
||||||
|
amplitudeTimer.cancel()
|
||||||
|
amplitudeTimer = Timer()
|
||||||
|
amplitudeTimer.scheduleAtFixedRate(getAmplitudeUpdateTask(), 0, AMPLITUDE_UPDATE_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
|
Reference in New Issue
Block a user