【发布时间】:2020-02-08 08:23:21
【问题描述】:
注意: 下面在 MyFirebaseMessageingService.java 中提到的代码
public class MyFirebaseMessagingService extends FirebaseMessagingService {
.......
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
..............
ValidateCall(validateRingerRequestModel, new ApiCallback() {
@Override
public void onResponse(boolean success, Object response) {
if (response != null) {
ValidateRingerResponseModel responseModel = (ValidateRingerResponseModel) response;
if (responseModel.status) {
Intent intent = new Intent(getApplicationContext(), Notification.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("data", model);
startActivity(intent);
}
}
}
});
}
“通知”是一个简单的活动,它显示一些带有点击事件操作的按钮。当应用程序在前台运行并且通知进来时,只有活动启动,但是当应用程序关闭或最小化或设备处于睡眠模式(电池保护模式或长时间不使用)时,上面的代码被执行但 Notification.java 活动没有打开。
具有较新 android 版本(如 android 9)的设备会遇到该问题,对于旧版本(如 android 6),它可以正常工作。
上面的代码是否遗漏了一些东西,或者是否有任何其他方式可以在所有 android 版本上运行?
请提出建议。谢谢。
【问题讨论】:
-
请同时发布您的通知生成器代码
标签: android firebase firebase-cloud-messaging android-notifications