- In Android 10, baresip must be started after boot from notification.

This commit is contained in:
Juha Heinanen
2020-04-22 08:48:28 +03:00
parent dc64dbf913
commit 4881605a24
3 changed files with 43 additions and 10 deletions

View File

@ -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())
}
}
}
}
}

View File

@ -148,6 +148,8 @@
<string name="incoming_call_from">Puhelu soittajalta</string>
<string name="transfer_request">Puhelun siirtopyyntö kohteeseen</string>
<string name="message_from">Viesti lähettäjältä</string>
<!-- Boot Completed Receiver -->
<string name="tap_to_start">Kosketa käynnistääksesi sovelluksen</string>
<!-- Calls Activity -->
<string name="call_history">Puheluhistoria</string>
<string name="call">Soita</string>

View File

@ -125,6 +125,8 @@
<string name="incoming_call_from">Call from</string>
<string name="transfer_request">Call transfer request to</string>
<string name="message_from">Message from</string>
<!-- Boot Completed Receiver -->
<string name="tap_to_start">Tap to start application</string>
<!-- Calls Activity -->
<string name="call_history">Call History</string>
<string name="call">Call</string>