我试图通过设置警报在某个时间呼叫广播接收器。它似乎根本没有被调用。我正在尝试使用 logcat 进行调试。
我的闹钟设置是这样的:
AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Calendar notifyAlarm = Calendar.getInstance();
notifyAlarm.set(Calendar.HOUR, 17);
notifyAlarm.set(Calendar.MINUTE, 00);
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 2378530, intent, 0);
alarm.set(AlarmManager.RTC_WAKEUP, notifyAlarm.getTimeInMillis(), pendingIntent);
我的接收器如下:
public class AlarmReceiver extends BroadcastReceiver {
private static final String TAG ="test receiver";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.v(TAG, "receiver called");
}
}
在清单中我也有:
</activity>
<receiver android:name="AlarmReceiver"></receiver>
</application>
任何帮助表示赞赏。