android - 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.
解决方案
现在有很多设备具有非常积极的电池保护程序,这会阻止推送传递到您的应用程序,因为操作系统只会在后台杀死您的应用程序。除了谷歌之外,几乎所有制造商的设备都有这个问题。看看这个帖子
我一直在处理同样的事情,我们所做的是检查设备上是否激活了任何电池优化,并向用户发送消息,让他知道他的推送体验会因此受到影响。
推荐阅读
- json - Swift Parse JSON 错误:没有与键 CodingKeys 关联的值(stringValue: \"_source\
- javascript - Vue:如何将属性动态绑定到新的 DOM 元素
- javascript - 加密,然后将访问令牌存储在 localStorage
- django - 当我将 Django 应用程序从一个系统复制到另一个系统时,如何确定要安装哪些依赖项?
- python - 如何使用 Python 将 CP1252 文本文件转换为 Ascii 以进行电子邮件导出?
- python - python如何提取字符串中两个已知单词之间的文本?
- ruby-on-rails - 如何在开发环境中跳过 before_filter
- python - 在 OpenCV 中将图像从极坐标逆变换为笛卡尔坐标
- javascript - Sequelize - 如何在多属关联中设置外键名称
- nlp - 在 BERT 中用预先计算的结果替换位置嵌入会导致预测结果不佳