Android 13下精确闹钟无法唤醒启动应用的问题求助
精确闹钟在Android 13(三星设备)无法唤醒启动应用的问题
正在为Android 13更新应用,该应用依赖精确闹钟功能:用户启用闹钟后,设备需在设定时间唤醒并自动启动应用。因时间精度要求极高,使用setExactAndAllowWhileIdle()函数配置闹钟。
该功能在旧版Android上运行正常,但在三星Android 13设备上,闹钟无法唤醒设备并启动应用。已开启应用的「闹钟和提醒」权限,且将电池使用设置为无限制,问题仍未解决。
代码实现(C++Builder,SDK33)
_di_JIntent Intent=TJIntent::Create(); _di_JPendingIntent PendingIntent; Intent->setClassName(TAndroidHelper::Context, StringToJString("com.embarcadero.firemonkey.FMXNativeActivity")); if(VERSION_ANDROID<12) PendingIntent = TJPendingIntent::JavaClass->getActivity(TAndroidHelper::Context, 1, Intent, 0); else PendingIntent = TJPendingIntent::JavaClass->getActivity(TAndroidHelper::Context, 1, Intent, TJPendingIntent::JavaClass->FLAG_IMMUTABLE); tm64 = new_timestamp; //new_timestamp is properly calculated, no issue here TAndroidHelper::AlarmManager->setExactAndAllowWhileIdle(TJAlarmManager::JavaClass->RTC_WAKEUP,tm64,PendingIntent);
清单文件权限与配置
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> <uses-permission android:name="com.android.alarm.permission.SET_ALARM" /> ... <activity android:name="com.embarcadero.firemonkey.FMXNativeActivity" android:label="MyApp" android:exported="true" android:configChanges="orientation|keyboard|keyboardHidden|screenSize" android:launchMode="singleTask"> <!-- Tell NativeActivity the name of our .so --> <meta-data android:name="android.app.lib_name" android:value="MyApp" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
调试信息
闹钟设置状态(执行adb shell dumpsys alarm)
闹钟已正确设置(设定时间为15:00):
RTC_WAKEUP #15: Alarm{8e3d5e9 type 0 origWhen 1685415625000 whenElapsed 1028338535 com.pyxis.MyApp} tag=*walarm*:com.pyxis.MyApp/com.embarcadero.firemonkey.FMXNativeActivity type=RTC_WAKEUP origWhen=2023-05-30 15:00:25.000 window=0 exactAllowReason=permission repeatInterval=0 count=0 flags=0x9 policyWhenElapsed: requester=+23m53s21ms app_standby=-12s957ms device_idle=-- battery_saver=-- tare=-12s957ms gms_manager=-- whenElapsed=+23m53s21ms maxWhenElapsed=+23m53s21ms operation=PendingIntent{f65426e: PendingIntentRecord{d143b2f com.pyxis.MyApp startActivity}} idle-options=Bundle[{android.pendingIntent.backgroundActivityAllowed=false, android:broadcast.temporaryAppAllowlistReasonCode=302, android:broadcast.temporaryAppAllowlistDuration=10000, android:broadcast.temporaryAppAllowlistReason=, android:broadcast.temporaryAppAllowlistType=0}]
闹钟触发记录
交付历史显示闹钟已触发:
u0a481: [tag=*walarm*:com.pyxis.MyApp/com.embarcadero.firemonkey.FMXNativeActivity origWhen=1685415625000 H=PI:d143b2f elapsed=1028338540 rtc=2023-05-30 15:00:25.005]
Logcat日志
日志显示闹钟已执行,但应用未启动:
05-30 15:00:25.009 3008 3074 I ChimeraSystemEventListener: appLaunchIntent package name is: com.pyxis.MyApp 05-30 15:00:25.010 3008 3631 I ActivityTaskManager: START u0 {flg=0x10000000 cmp=com.pyxis.MyApp/com.embarcadero.firemonkey.FMXNativeActivity} from uid 10481 05-30 15:00:25.012 3008 3631 W ActivityTaskManager: Background activity start [callingPackage: com.pyxis.MyApp; callingUid: 10481; appSwitchState: 2; isCallingUidForeground: false; callingUidHasAnyVisibleWindow: false; callingUidProcState: NONEXISTENT; isCallingUidPersistentSystemProcess: false; realCallingUid: 1000; isRealCallingUidForeground: false; realCallingUidHasAnyVisibleWindow: false; realCallingUidProcState: PERSISTENT; isRealCallingUidPersistentSystemProcess: true; originatingPendingIntent: PendingIntentRecord{c7b08e5 com.pyxis.MyApp startActivity}; allowBackgroundActivityStart: false; intent: Intent { flg=0x10000000 cmp=com.pyxis.MyApp/com.embarcadero.firemonkey.FMXNativeActivity }; callerApp: null; inVisibleTask: false] 05-30 15:00:25.015 3008 3631 D ActivityTaskManager: TaskLaunchParamsModifier:task=null activity=ActivityRecord{d88638b u0 com.pyxis.MyApp/com.embarcadero.firemonkey.FMXNativeActivity} display-from-caller=0 display-id=0 display-windowing-mode=1 suggested-display-area=DefaultTaskDisplayArea@260047950 05-30 15:00:25.015 3008 3631 D [secipm]: mSecIpmManager Preload com.pyxis.MyApp dex files 05-30 15:00:25.016 3008 3631 D ActivityTaskManager: TaskLaunchParamsModifier:task=null activity=ActivityRecord{d88638b u0 com.pyxis.MyApp/com.embarcadero.firemonkey.FMXNativeActivity} t-1} display-from-caller=0 display-id=0 display-windowing-mode=1 suggested-display-area=DefaultTaskDisplayArea@260047950 non-freeform-display display-area=DefaultTaskDisplayArea@260047950 maximized-bounds 05-30 15:00:25.017 3008 3631 E ActivityTaskManager: Abort background activity starts from 10481 05-30 15:00:25.017 3008 18565 D PkgPredictorService-IpmAdcpController: create a new DexPreloadTask pkg:com.pyxis.MyApp path:/data/app/~~xalia7OAHFWvyR5VF9ZSEw==/com.pyxis.MyApp-HJ8-6O36vZZoJVoSXqGryA== 05-30 15:00:25.017 3008 3631 D ActivityTaskManager: startActivity: reason=PendingIntentRecord, result=102 05-30 15:00:25.017 3008 3631 D ActivityManager: Received ACTIVITY intent 0xc7b08e5 Key{startActivity pkg=com.pyxis.MyApp intent=flg=0x10000000 cmp=com.pyxis.MyApp/com.embarcadero.firemonkey.FMXNativeActivity flags=0x4000000 u=0} requestCode=1 res=0 from uid 1000
疑问与求助
- 代码中
Intent->setClassName(TAndroidHelper::Context, StringToJString("com.embarcadero.firemonkey.FMXNativeActivity"));的写法是否正确? - 是否缺少必要的Intent标志位?
- 如何解决Android 13下闹钟触发后无法启动应用的问题?
内容的提问来源于stack exchange,提问作者Tim Beurk
相关产品推荐
相关产品推荐

