Page 1 of 1

Wie können Sie den echten Start auf Android 15 erkennen, da Action_boot_Completed darauf unterbrochen ist?

Posted: 05 Sep 2025, 02:31
by Anonymous
Hintergrund
bis Android 14, verwendete mit action_boot_completed gut, um den OS -Start zu erfassen, um dort Dinge zu tun:
bootreceiver.kt

Code: Select all

class BootReceiver : BroadcastReceiver() {

@SuppressLint("UnsafeProtectedBroadcastReceiver")
@UiThread
override fun onReceive(context: Context, intent: Intent) {
...
Manifest

Code: Select all


...








Das Problem
scheint, dass Sie bei Android 15 diese Absicht auch für verschiedene andere Fälle erhalten, z. />
https://issuetracker.google.com/issues/384486455
https://issuetracker.google.com/issues/ ... /sues/sues AddApplicationStartInfocPompletionListener (verfügbar bei Android API 34, der Android 14 ist, sollte also in Ordnung sein):
https://developer.android.com/reference ... onListener(java.util.Concurrent /> Dann überprüfen Sie den Grund dafür:
https://developer.android.com/reference ... getSason()
und wenn es start_reason_boot_complete ist. />

Code: Select all

inline fun  Context.getSystemServiceCompat(): T =
ContextCompat.getSystemService(applicationContext, T::class.java)!!

...

val activityManager: ActivityManager = context.getSystemServiceCompat()
activityManager.addApplicationStartInfoCompletionListener(ExecutorEx.diskIO) { applicationStartInfo ->
val reasonStr = when (val reason = applicationStartInfo.reason) {
ApplicationStartInfo.START_REASON_ALARM -> "START_REASON_ALARM"
ApplicationStartInfo.START_REASON_BACKUP -> "START_REASON_BACKUP"
ApplicationStartInfo.START_REASON_BOOT_COMPLETE -> "START_REASON_BOOT_COMPLETE"
ApplicationStartInfo.START_REASON_BROADCAST -> "START_REASON_BROADCAST"
ApplicationStartInfo.START_REASON_CONTENT_PROVIDER -> "START_REASON_CONTENT_PROVIDER"
ApplicationStartInfo.START_REASON_JOB -> "START_REASON_JOB"
ApplicationStartInfo.START_REASON_LAUNCHER -> "START_REASON_LAUNCHER"
ApplicationStartInfo.START_REASON_LAUNCHER_RECENTS -> "START_REASON_LAUNCHER_RECENTS"
ApplicationStartInfo.START_REASON_OTHER -> "START_REASON_OTHER"
ApplicationStartInfo.START_REASON_PUSH -> "START_REASON_PUSH"
ApplicationStartInfo.START_REASON_SERVICE -> "START_REASON_SERVICE"
ApplicationStartInfo.START_REASON_START_ACTIVITY -> "START_REASON_START_ACTIVITY"
else -> {
logException("unknown applicationStartInfo reason:$reason")
"Unknown:$reason"
}
}
Log.d("AppLog", "reasonStr:$reasonStr")
Anstelle dieses Wertes im Boot habe ich jedoch start_reason_broadcast ...
Ganz zu schweigen davon, dass dies über einen Rückruf, nicht direkt im BootReceiver Klasse> Klasse> Klasse, in Onreceive ...
Ich habe auch die Intent von beiden Fällen überprüft. different:
  • For fake boot (meaning just launching the app), the flags are 0x9000030
  • For a real boot, the flags are 0x89000010
The questions

Is there any reliable Weg, um einen echten Start zu erkennen, insbesondere in der von mir erstellten BOOTRECEIVER -Klasse, unter Android 15?>