【发布时间】:2019-04-04 17:09:05
【问题描述】:
自从我实现 FCM 数据消息以来,我一直试图通过查看我的应用程序服务来让我的应用程序前台服务在 Oreo 上保持活动状态,但我发现应用程序变得不活动,当我没有发生这种情况时正在发送 FCM 通知消息。
这是我用来捕获数据消息的代码:
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
// Cordova Callback
FCMPlugin.sendPushPayload(data);
Intent resultIntent = new Intent(this , FCMPluginActivity.class);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this,0 , resultIntent,PendingIntent.FLAG_ONE_SHOT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mBuilder = new Builder(this, "0");
}else{
mBuilder = new Builder(this);
}
mBuilder.setSmallIcon(getApplicationInfo().icon)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(false)
.setContentIntent(resultPendingIntent);
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O){
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel notificationChannel = new NotificationChannel("0", "Playback status", importance);
notificationChannel.setShowBadge(false);
assert mNotificationManager != null;
mNotificationManager.createNotificationChannel(notificationChannel);
}
assert mNotificationManager != null;
mNotificationManager.notify(0, mBuilder.build());
}
如何使用 FCM 数据消息让我的应用前台服务在 Oreo 上保持活跃?
【问题讨论】:
标签: firebase firebase-cloud-messaging android-8.0-oreo foreground-service cordova-plugin-fcm