[英]Android: why doesn't AlarmManager work?
我有以下代碼。 應該以一定的間隔在logcat中發送消息但是不起作用。 stackoverflow上有很多類似的帖子,但我無法弄清楚問題。 在某處可以幫助我的brainiac嗎?
<receiver android:name="BoopoohooAlarmReceiver"></receiver>
public void startAlarmManager(long interval){
Context context = getApplicationContext();
Intent intent = new Intent(context, BoopoohooAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 10);
Log.i(DEBUG, "hollaa");
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), interval, pendingIntent);
}
public class BoopoohooAlarmReceiver extends BroadcastReceiver {
private final String DEBUG = "BoopoohooAlarmReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(DEBUG, "onReceive");
}
}
謝謝。
嘗試添加“。” (點)在android清單文件聲明中的接收者名稱前面。
<receiver android:name=".BoopoohooAlarmReceiver"></receiver>
這也可能有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.