- In Android 10, baresip must be started after boot from notification.
This commit is contained in:
@@ -1,31 +1,60 @@
|
|||||||
package com.tutpro.baresip
|
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.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.provider.Settings.Global.getString
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
|
|
||||||
class BootCompletedReceiver : BroadcastReceiver() {
|
class BootCompletedReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
|
||||||
Log.i("Baresip", "BootCompletedReceiver received intent ${intent.action}")
|
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 configPath = context.filesDir.absolutePath + "/config"
|
val config = String(Utils.getFileContents(configPath)!!, StandardCharsets.ISO_8859_1)
|
||||||
val config = String(Utils.getFileContents(configPath)!!, StandardCharsets.ISO_8859_1)
|
val asCv = Utils.getNameValue(config,"auto_start")
|
||||||
val asCv = Utils.getNameValue(config,"auto_start")
|
|
||||||
if ((asCv.size > 0) && (asCv[0] == "yes")) {
|
if ((asCv.size > 0) && (asCv[0] == "yes")) {
|
||||||
Log.i("Baresip", "Start baresip upon boot completed or restart")
|
|
||||||
val i = Intent(context, MainActivity::class.java)
|
Log.i("Baresip", "Start baresip upon boot completed")
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
|
val i = Intent(context, MainActivity::class.java).apply {
|
||||||
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
val b = Bundle()
|
val b = Bundle()
|
||||||
b.putBoolean("onStartup", true)
|
b.putBoolean("onStartup", true)
|
||||||
i.putExtras(b)
|
putExtras(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT < 29) {
|
||||||
context.startActivity(i)
|
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="incoming_call_from">Puhelu soittajalta</string>
|
||||||
<string name="transfer_request">Puhelun siirtopyyntö kohteeseen</string>
|
<string name="transfer_request">Puhelun siirtopyyntö kohteeseen</string>
|
||||||
<string name="message_from">Viesti lähettäjältä</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 -->
|
<!-- Calls Activity -->
|
||||||
<string name="call_history">Puheluhistoria</string>
|
<string name="call_history">Puheluhistoria</string>
|
||||||
<string name="call">Soita</string>
|
<string name="call">Soita</string>
|
||||||
|
|||||||
@@ -125,6 +125,8 @@
|
|||||||
<string name="incoming_call_from">Call from</string>
|
<string name="incoming_call_from">Call from</string>
|
||||||
<string name="transfer_request">Call transfer request to</string>
|
<string name="transfer_request">Call transfer request to</string>
|
||||||
<string name="message_from">Message from</string>
|
<string name="message_from">Message from</string>
|
||||||
|
<!-- Boot Completed Receiver -->
|
||||||
|
<string name="tap_to_start">Tap to start application</string>
|
||||||
<!-- Calls Activity -->
|
<!-- Calls Activity -->
|
||||||
<string name="call_history">Call History</string>
|
<string name="call_history">Call History</string>
|
||||||
<string name="call">Call</string>
|
<string name="call">Call</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user