警报响起时,AlarmManager不会触发意图

时间:2018-08-01 07:39:38

标签: android alarmmanager android-pendingintent android-broadcastreceiver

即使我设置了警报并注册了广播接收器,警报也没有激发意图。

我在这里注册接收者:-

private void registerOfflineEntitlementUpdateReceiver(Context context) {
    IntentFilter intentFilter = new IntentFilter(ENTITLEMENT_OFFLINE_ACTION);
    LocalBroadcastManager.getInstance(context).registerReceiver(new EntitlementOfflineUpdateReceiver() , intentFilter);
}

警报设置在这里:-

private void setAlarm() {
    Intent intent = new Intent(mContext, EntitlementOfflineUpdateReceiver.class);
    intent.setAction(ENTITLEMENT_OFFLINE_ACTION);
    mPending = PendingIntent.getBroadcast(mContext, Constants.ENTITLEMENT_OFFLINE_ALARM, intent, 0);

    mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
    mAlarmManager.cancel(mPending);

    Calendar cal = Calendar.getInstance();
    long cncNextPollTimeInMillis = ApplicationPrefs.getInstance(mContext).getNextCncHelloPoll();
    cal.setTimeInMillis(cncNextPollTimeInMillis);
    int a_SEC = 1000;
    int a_MIN = a_SEC * 60;
    cal.add(Calendar.MILLISECOND, a_MIN);
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC, cal.getTimeInMillis(), mPending);
    }
    else {
        mAlarmManager.set(AlarmManager.RTC,cal.getTimeInMillis(),mPending);
    }
}

广播接收器类:-

public class EntitlementOfflineUpdateReceiver extends BroadcastReceiver {
    private String TAG = "SMC.EntitlementOfflineUpdateReceiver";
    @Override
    public void onReceive(final Context context, Intent intent) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Log.i(TAG, "performing offline entitlement update ...");
                EntitlementEngine.getInstance(context).performOfflineEntitlementUpdate();
            }
        }).start();

    }
}

我得到的实际错误是什么?

0 个答案:

没有答案