From 9dd929b177957776c1c1c30acdfe554bb4af460a Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Thu, 13 Oct 2022 13:33:01 +1300 Subject: [PATCH] Handle missing intent extras in TimerService This might fix an error I was seeing on production in the Play store. --- android/app/src/main/java/com/massive/TimerService.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/java/com/massive/TimerService.kt b/android/app/src/main/java/com/massive/TimerService.kt index 47be0d3..b991bd6 100644 --- a/android/app/src/main/java/com/massive/TimerService.kt +++ b/android/app/src/main/java/com/massive/TimerService.kt @@ -25,15 +25,15 @@ class TimerService() : Service() { @RequiresApi(Build.VERSION_CODES.O) override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - vibrate = intent!!.extras!!.getBoolean("vibrate") - sound = intent.extras?.getString("sound") + vibrate = intent?.extras?.getBoolean("vibrate") == true + sound = intent?.extras?.getString("sound") manager?.cancel(NOTIFICATION_ID_DONE) applicationContext.stopService(Intent(applicationContext, AlarmService::class.java)) - if (intent.action == "add") { + if (intent?.action == "add") { endMs = currentMs.toInt().plus(60000) applicationContext.stopService(Intent(applicationContext, AlarmService::class.java)) } else { - endMs = intent.extras!!.getInt("milliseconds") + endMs = intent?.extras!!.getInt("milliseconds") } Log.d("TimerService", "endMs=$endMs,currentMs=$currentMs,vibrate=$vibrate,sound=$sound") manager = getManager(applicationContext)