簡體   English   中英

應用程序不在內存中時(One Plus 3)未收到警報管理器廣播

[英]Alarm Manager broadcast not received when app is not in memory (One Plus 3)

當應用程序不在內存中(從應用程序托盤中滑出)時,在某些設備中未收到Alarm Manager廣播。 無法使用的設備使用API​​ 25運行,並且是ONE PLUS 3設備。 但是在Nexus 6(使用API​​ 25)中也可以使用。

奇怪的是,我可以在系統日志中看到警報正在觸發。 當警報響起時,我可以在下面看到日志。 只是沒有收到broadCast。 同樣,僅當應用程序不在內存中時,才會發生這種情況。 當應用程序在內存中時,可以正確接收廣播。

V/AlarmManager: Triggering alarm #0: 0 when =1508843147121 package=net.IntAppoperation =*walarm*:com.intapp.receivers.NOTIFICATION_ALARM

這是我設置鬧鍾的方式

在清單中:

<receiver android:name="com.intapp.receivers.ReminderReceiver"
              android:exported="false"
              android:enabled="true">
        <intent-filter>
            <action android:name="com.intapp.receivers.NOTIFICATION_ALARM" />
        </intent-filter>
</receiver>

然后當我想設置警報時:

public static final String ACTION = "com.intapp.receivers.NOTIFICATION_ALARM";

AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, ReminderReceiver.class);
intent.setAction(ACTION);
int randomNum = new Random().nextInt(Integer.MAX_VALUE - 1 + 1);
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, randomNum, intent, PendingIntent.FLAG_ONE_SHOT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
     alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent); // I get time from calendar instance in my function
  } else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);
            } else {
                alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);
            }
}

這是我的Receiver的實現:

public class ReminderReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "Receiver called ");
        // my implementation 
     }
}

編輯:

好像問題更大了。 我還注冊了CALL_STATE ,可以通過它收聽傳入/傳出的呼叫。 當應用程序不在內存中時,該廣播接收器也不會觸發。 另外,這也發生在同樣在API 25上運行的Samsung設備上。某些設備上的API 25是否已知此問題(清單廣播不起作用)?

我也有一個OnePlus 3 ...是的,這對我也很常見。 即使我注冊了BootReceiver 我通過卸載並重新安裝應用程序解決了問題。

我建議在您的Application實現WakeLock ,以防止設備殺死您的應用程序,因此BroadcastReceiver保持活動狀態。

讓我們希望OnePlus將來會做得更好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM