问题描述
需要:当警报触发时,使用警报管理器启动应用程序。
已尝试: broadCast Receiver用于接收警报触发器并启动应用程序,但不启动应用程序。
@Override
public void onReceive(final Context context,Intent intent) {
Intent myIntent = new Intent(context,MainActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
设置闹钟:
public void startAlarm(Context context) {
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this,RestartServicebroadcastReceiver.class);
PendingIntent alarmIntent = PendingIntent.getbroadcast(context,intent,PendingIntent.FLAG_CANCEL_CURRENT);
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP,Calendar.getInstance().getTimeInMillis(),AlarmManager.INTERVAL_HOUR,alarmIntent);
}
清单:
<receiver android:name="com.android.cchhaatt.RestartServicebroadcastReceiver"
android:enabled="true"
android:exported="true"
android:label="StartMyServiceAtBootReceiver"
android:process=":remote">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)