我想在系统启动时运行重复警报。这是代码:
// Run the SendService once an hour
@Override
public void onReceive(Context context, Intent intent) {
//Logger.getInstance().writeLine(getClass().getName(), "Received boot, start SMS repeating alarm");
Toast.makeText(context, "Starting SMS2Mail alarm on boot", Toast.LENGTH_LONG).show();
Intent svcIntent = new Intent(context, MessageFileService.class);
svcIntent.setAction(MessageFileService.GET_INTENT);
sendSMSIntent = PendingIntent.getBroadcast(context, 0, svcIntent, 0);
alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
AlarmManager.INTERVAL_FIFTEEN_MINUTES,
AlarmManager.INTERVAL_HOUR, sendSMSIntent);
}
清单有
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
和
<service
android:name="com.cio1.sms2mail.StartSendService"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</service>
就我的任何调试资源而言,AlarmManager 根本不会触发。此外,有关如何从启动时恢复 LogCat 信息的任何线索都会有所帮助。另外,这是否与此处提到的对广播接收器的限制有关?谢谢。