当系统警报设置

时间:2016-03-01 08:29:01

标签: android

calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);  
calendar.set(Calendar.HOUR_OF_DAY, 1);
PendingIntent pi = PendingIntent.getService(context, 0, new Intent(context,MyClass.class),PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 7*24*60*60*1000, pi);

我有这个简单的挂起重复警报,只有在没有设置系统安卓警报时才能正常工作。在系统警报应用程序中设置警报的时间无关紧要,看起来这个系统应用程序会停止我所有待处理的意图。知道如何调试这个吗?什么可能导致这个问题? 我想在系统报警的paralel中使用它。

1 个答案:

答案 0 :(得分:1)

确保您有权限

<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

用于调试:

在您的活动onNewIntent()活动中覆盖MyClass,如下所示:

@Override
onNewIntent(Intent intent){
    android.os.Debug.waitForDebugger();
    if(intent.hasExtra("alarm")){           //Put a break point here
        Log.d("Alarm fired","yes");
    }
}

创建PendingIntent以触发警报,如下所示:

Intent intent=new Intent(context,MyClass.class);
intent.putExtra("alarm","yes");
PendingIntent pi = PendingIntent.getService(context, 0, intent,0);

因此,当您的警报被触发时,控制权将转到onNewIntent并等待您附加调试器。那个时候去android studio中附加调试器按钮并将调试器附加到你的应用程序。这就是你怎么知道你的警报被解雇了。

相关问题