From 4881605a24feeb226584fb63417dc7bca2b523af Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Wed, 22 Apr 2020 08:48:28 +0300 Subject: [PATCH] - In Android 10, baresip must be started after boot from notification. --- .../tutpro/baresip/BootCompletedReceiver.kt | 49 +++++++++++++++---- app/src/main/res/values-fi/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BootCompletedReceiver.kt b/app/src/main/kotlin/com/tutpro/baresip/BootCompletedReceiver.kt index 53e4cac7..6fcfec78 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BootCompletedReceiver.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BootCompletedReceiver.kt @@ -1,31 +1,60 @@ package com.tutpro.baresip +import android.app.NotificationChannel +import android.app.NotificationManager +import android.app.PendingIntent +import android.app.Service import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.os.Build import android.os.Bundle +import android.provider.Settings.Global.getString +import androidx.core.app.NotificationCompat import java.nio.charset.StandardCharsets class BootCompletedReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { + Log.i("Baresip", "BootCompletedReceiver received intent ${intent.action}") - if ((intent.action == Intent.ACTION_BOOT_COMPLETED) or - (intent.action == "com.tutpro.baresip.Restart")) { - val configPath = context.filesDir.absolutePath + "/config" - val config = String(Utils.getFileContents(configPath)!!, StandardCharsets.ISO_8859_1) - val asCv = Utils.getNameValue(config,"auto_start") - if ((asCv.size > 0) && (asCv[0] == "yes")) { - Log.i("Baresip", "Start baresip upon boot completed or restart") - val i = Intent(context, MainActivity::class.java) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + + val configPath = context.filesDir.absolutePath + "/config" + val config = String(Utils.getFileContents(configPath)!!, StandardCharsets.ISO_8859_1) + val asCv = Utils.getNameValue(config,"auto_start") + + if ((asCv.size > 0) && (asCv[0] == "yes")) { + + Log.i("Baresip", "Start baresip upon boot completed") + + val i = Intent(context, MainActivity::class.java).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) val b = Bundle() b.putBoolean("onStartup", true) - i.putExtras(b) + putExtras(b) + } + + if (Build.VERSION.SDK_INT < 29) { context.startActivity(i) + } else { + val nm = context.getSystemService(Service.NOTIFICATION_SERVICE) as NotificationManager + val channel = NotificationChannel("default", "default", + NotificationManager.IMPORTANCE_DEFAULT) + nm.createNotificationChannel(channel) + val START_NOTIFICATION_IN = 105 + val pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_ONE_SHOT) + with(NotificationCompat.Builder(context, "default")) { + setSmallIcon(R.drawable.ic_stat) + setContentTitle(context.getString(R.string.app_name)) + setContentText(context.getString(R.string.tap_to_start)) + setContentIntent(pi) + setAutoCancel(true) + nm.notify(START_NOTIFICATION_IN, build()) + } } } + } } \ No newline at end of file diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 4e6cfe26..295356b3 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -148,6 +148,8 @@ Puhelu soittajalta Puhelun siirtopyyntö kohteeseen Viesti lähettäjältä + + Kosketa käynnistääksesi sovelluksen Puheluhistoria Soita diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 36acac49..388fcf78 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -125,6 +125,8 @@ Call from Call transfer request to Message from + + Tap to start application Call History Call