Firebase发出太多警报

时间:2016-10-17 07:09:16

标签: android firebase firebase-cloud-messaging android-alarms

我已经有一个每天都会发出FLAG_UPDATE_CURRENT的警报。这是开发人员控制台的日志。

java.lang.SecurityException: !@Too many alarms (500) registered from pid 32326 uid 10206
    at android.os.Parcel.readException(Parcel.java:1540)
    at android.os.Parcel.readException(Parcel.java:1493)
    at android.app.IAlarmManager$Stub$Proxy.set(IAlarmManager.java:206)
    at android.app.AlarmManager.setImpl(AlarmManager.java:428)
    at android.app.AlarmManager.set(AlarmManager.java:215)
    at com.google.firebase.iid.FirebaseInstanceIdService.zzagl(Unknown Source)
    at com.google.firebase.iid.FirebaseInstanceIdService.zzd(Unknown Source)
    at com.google.firebase.iid.FirebaseInstanceIdService.zza(Unknown Source)
    at com.google.firebase.iid.FirebaseInstanceIdService.zzm(Unknown Source)
    at com.google.firebase.iid.zzb$2.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:818)

我正在使用 Firebase 9.6.1

更新

public static void setAlarm(Context context, boolean isSet) {
  try {
     AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
     Intent intent = new Intent(context, AlarmReceiver.class);

     boolean isWorking = (PendingIntent.getBroadcast(context,
                SettingsActivity.REQUEST_CODE, intent, PendingIntent.FLAG_NO_CREATE) != null);

     if (isSet && !isWorking) {
        PendingIntent sender = PendingIntent.getBroadcast(context,
                                   SettingsActivity.REQUEST_CODE, intent, 
                                   PendingIntent.FLAG_UPDATE_CURRENT);

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());

        calendar.set(Calendar.HOUR, 10);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);

        am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                               AlarmManager.INTERVAL_DAY, sender);
      } else {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
                                      SettingsActivity.REQUEST_CODE, intent,
                                      PendingIntent.FLAG_CANCEL_CURRENT);
        am.cancel(pendingIntent);
        pendingIntent.cancel();
      }
  } catch (Exception e) {
      Crashlytics.logException(e);
  }
}

1 个答案:

答案 0 :(得分:2)

根据this thread,Firebase团队已在10.0版本中修复了该错误。发行说明为here