我一直在尝试使用 AlarmManager 和 BroadCastReceiver 设置我的第一个警报,如下所述:http: //smartandroidians.blogspot.com.es/2010/04/alarmmanager-and-notification-in.html
我的设置:
AndroidManifest.xml:
<receiver android:name="es.radiopodcastellano.player.SleepAlarm" />
我的主要活动 onCreate (此代码实际上驻留在子类中,但为了简化我把它放在那里):
@Override
public void onCreate(Bundle savedInstanceState) {
// <Stripped code>
AlarmManager alarm = (AlarmManager) currentContext.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this.getApplicationContext(), SleepAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
alarm.set(AlarmManager.RTC_WAKEUP,(System.currentTimeMillis() + (5 * 1000)),pendingIntent);
}
睡眠警报.java:
public class SleepAlarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("RPod_SleepAlarm","Alarm!!");
}
}
“adb shell dumpsys alarm”的输出显示了这一点,因此似乎正在调用意图:
es.radiopodcastellano.player
221ms running, 32 wakeups
44 alarms: flg=0x4 cmp=es.radiopodcastellano.player/.SleepAlarm
但是,Logcat 没有显示“RPod_SleepAlarm”标签。我可能做错了什么?