我一直在尝试使用AlarmManager和BroadCastReceiver设置我的第一个警报,如下所述:http://smartandroidians.blogspot.com.es/2010/04/alarmmanager-and-notification-in.html

我的设置:

AndroidManifest.xml:

<receiver android:name="es.radiopodcastellano.player.SleepAlarm" />

我的主要Activity 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);
}

SleepAlarm.java:
public class SleepAlarm extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Log.d("RPod_SleepAlarm","Alarm!!");
}

}

“adb shell dumpsys警报”的输出显示了这一点,因此似乎正在调用该意图:
  es.radiopodcastellano.player
221ms running, 32 wakeups
44 alarms: flg=0x4 cmp=es.radiopodcastellano.player/.SleepAlarm

但是,Logcat对于“RPod_SleepAlarm”标记不显示任何内容。我可能做错了什么?

最佳答案

我发现了问题。

清单上的接收者位于小部件的另一个接收者内部,并且它必须是应用程序的子代。因此,如果您的行为与我相同,请检查是否已正确设置AndroidManifest.xml:

10-07 19:22
查看更多