If the app was updated try to start the service again

This commit is contained in:
greenart7c3
2024-10-14 11:29:39 -03:00
parent 364362f09b
commit e3595db332
2 changed files with 25 additions and 1 deletions
+1
View File
@@ -35,6 +35,7 @@
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@@ -3,6 +3,7 @@ package com.greenart7c3.nostrsigner.service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import com.greenart7c3.nostrsigner.BuildConfig
@@ -11,8 +12,30 @@ class BootReceiver : BroadcastReceiver() {
@Suppress("KotlinConstantConditions")
if (BuildConfig.FLAVOR == "offline") return
if (intent.action == Intent.ACTION_PACKAGE_REPLACED && Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
if (intent.dataString?.contains("com.greenart7c3.nostrsigner") == true) {
Log.d("BootReceiver", "Starting ConnectivityService ACTION_PACKAGE_REPLACED")
context.startForegroundService(
Intent(
context,
ConnectivityService::class.java,
),
)
}
}
if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED) {
Log.d("BootReceiver", "Starting ConnectivityService ACTION_MY_PACKAGE_REPLACED")
context.startForegroundService(
Intent(
context,
ConnectivityService::class.java,
),
)
}
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
Log.d("BootReceiver", "Starting ConnectivityService")
Log.d("BootReceiver", "Starting ConnectivityService ACTION_BOOT_COMPLETED")
context.startForegroundService(
Intent(
context,