AlarmManager永远不会工作

时间:2016-06-15 16:30:36

标签: android alarmmanager

我看到了所有问题和答案,但我没有找到解决问题的方法。我的警报(或PendingIntent)永远不会被解雇。这是我的代码:

清单

    <receiver
        android:name=".colorevent.receiver.ConfigureEventAlarmsReceiver"
        android:exported="false"
        android:process=":remote" >
        <intent-filter>
            <action android:name="iupix.mobile.CONFIGURE_EVENT_ACTION"/>
        </intent-filter>
    </receiver>

警报创建

AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

Bundle extras = new Bundle();
extras.putInt(ConfigureEventAlarmsReceiver.EVENT_ID, 1);

Intent intent = new Intent(context, ConfigureEventAlarmsReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_ONE_SHOT);

Calendar time = Calendar.getInstance();
time.add(Calendar.SECOND, 10);

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    alarmMgr.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, time.getTimeInMillis(), pendingIntent);
}else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    alarmMgr.setExact(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pendingIntent);
}else{
    alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, time.getTimeInMillis(), pendingIntent);
}

广播接收器

public class ConfigureEventAlarmsReceiver extends BroadcastReceiver {

    public static final String CONFIGURE_EVENT_ACTION = "iupix.mobile.CONFIGURE_EVENT_ACTION";

    public static final String EVENT_ID = "EVENT_ID";

    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction() != null && intent.getAction().equals(CONFIGURE_EVENT_ACTION)) {
            Bundle extras = intent.getExtras();

            if(extras != null) {
                if(extras.containsKey(EVENT_ID)) {
                    int eventId = extras.getInt(EVENT_ID);
                    this.configureAlarmsForEvent(context, eventId);
                }
            }
        }
    }
}

有什么想法吗?拜托,我真的不知道该怎么做。

谢谢!

0 个答案:

没有答案