安卓:为什么闹钟管理器(AlarmManager)不能正常工作?

3
我有下面的代码,它应该可以在一定时间间隔内发送消息给logcat,但是它没有起作用。stackoverflow上有很多类似的帖子,但我无法找到问题所在。有没有聪明人能帮我解决?
<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");
    }
}

感谢您的选择。
2个回答

6
尝试在Android清单文件声明中接收者名称前添加“。”(点)。
<receiver android:name=".BoopoohooAlarmReceiver"></receiver>

This may help too.


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接