首页 > 解决方案 > FCM push not wokring in one plus 8

问题描述

I have tried the following solution but it stops working my push notification. I just wanted to stop my firebase service from getting killed by doze mode. I tried different solutions like sending priority as high in payload but that also didn't work.

 <service android:name=".backgroundmanager.BackgroundOperationsManagerService" android:enabled="true" android:process="com.hashedin.processname" />



 AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
            Intent intent = new Intent(this, AlarmBroadCastReceiver.class);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
            ALARM_REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            if (Build.VERSION.SDK_INT >= 23) {
             alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, 30000, pendingIntent);
            }
            else if (Build.VERSION.SDK_INT >= 19) {
             alarmManager.setExact(AlarmManager.RTC_WAKEUP, 30000, pendingIntent);
            } else {
            alarmManager.set(AlarmManager.RTC_WAKEUP, 30000, pendingIntent);
            }

<receiver android:name=".backgroundmanager.alarmmanager.AlarmBroadCastReceiver"
android:enabled="true"
android:process="com.hashedin.processname"/>

public class AlarmBroadCastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        {
            PowerManager.WakeLock  screenWakeLock;
            Toast.makeText(context, "broadcast fired", Toast.LENGTH_LONG).show();
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            screenWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                        "myapp:ScreenLock tag from AlarmListener");
            screenWakeLock.acquire(10*60*1000L /*10 minutes*/);

            Intent service = new Intent(context, AppFireBaseMessagingService.class);
            startWakefulService(context, service);
            screenWakeLock.release();
        }

    }
}

It works when the app is opened but when it is killed it does not work.

标签: androidpush-notificationfirebase-cloud-messaging

解决方案


现在有很多设备具有非常积极的电池保护程序,这会阻止推送传递到您的应用程序,因为操作系统只会在后台杀死您的应用程序。除了谷歌之外,几乎所有制造商的设备都有这个问题。看看这个帖子

我一直在处理同样的事情,我们所做的是检查设备上是否激活了任何电池优化,并向用户发送消息,让他知道他的推送体验会因此受到影响。


推荐阅读