- In Android 10, baresip must be started after boot from notification.
This commit is contained in:
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
Reference in New Issue
Block a user