我已经实施了Firebase,但不幸的是,通知只在应用处于前台或后台时工作,但无法在应用关闭时收到任何通知。我尝试在网上冲浪,但无法获得任何结果。 即使在关闭它后,有什么办法让应用程序保持活跃状态? 如果是,我认为这将有助于收到通知。任何有用的建议都受到欢迎。谢谢FCM推送通知在前台和后台工作,但在应用关闭时无法工作
-2
A
回答
0
我做的一件事是我不依赖通知响应,而是传递数据对象并自己做出自定义通知。
下面是代码,可以帮助你,因为我们可以访问数据,即使对象时,应用程序是开放及关闭的:
Map<String, String> dataMap = remoteMessage.getData();
String notif = dataMap.get("title");
然后我使用此功能进行通知
private void notificationManager(Context context, String message) {
try {
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Log.v("message", "," + message);
Intent notificationIntent = new Intent(context, SplashActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setAutoCancel(true);
builder.setContentTitle(context.getString(R.string.app_name));
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
builder.setContentText(message);
builder.setTicker(message);
builder.setLights(Color.GREEN, 500, 500);
builder.setWhen(when);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentIntent(intent);
Notification notification = builder.build();
notification.ledARGB = 0xFFff0000;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
notification.ledOnMS = 100;
notification.ledOffMS = 100;
notificationManager.notify(1, notification);
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire(15000);
} catch (Exception e) {
e.printStackTrace();
}
}
希望这有助于。
0
FCM有可能你正在使用的消息显示两个消息服务
- 显示消息
- 数据消息
。您应该使用数据消息而不是显示消息。当应用关闭时,显示消息将无法使用。
相关问题
- 1. 无法使用FCM在前台接收推送通知
- 2. APNS在前台但不是后台推送工作
- 3. 无声推送通知在后台模式下无法在iOS7上工作
- 4. FCM推送通知没有收到当应用程序在前台,但收到当应用程序在后台
- 5. 应用程序在后台工作时无法正常工作
- 6. 离子android推送通知只在后台工作
- 7. FCM通知,通知时,请单击应用程序在前台后台不
- 8. Worklight:应用程序无法在前台收到推送通知
- 9. 在前台工作正常的进程在后台无法正常工作
- 10. 我在IOS上没有在后台接收fcm推送通知
- 11. 当APP在后台时iOS无声推送不工作
- 12. Android后台通知不工作在Firebase
- 13. Firebase通知不在后台工作
- 14. 推送通知FCM在应用程序处于后台时不会显示
- 15. 的iOS FCM通知从谷歌控制台工作,但无法从服务器
- 16. 无法让推送通知工作
- 17. 前台推送通知
- 18. FCM推送通知自动关闭
- 19. 应用程序关闭时未收到Android FCM推送通知
- 20. didEnterRegion在前台工作,但不在后台或其他VC
- 21. 当应用程序在前台时未收到推送通知
- 22. 在后台工作
- 23. 当应用程序处于后台或未运行时,推送通知无法正常工作
- 24. CocoaAsyncSocket在后台无法工作
- 25. 当应用程序从后台转到前台时,忽略推送通知
- 26. WP7推送通知在应用发布后无法正常工作
- 27. 当应用程序在后台时不显示推送通知
- 28. 当应用程序在后台时的Android-Firebase推送通知
- 29. 当应用程序在后台时推送通知
- 30. 部署新战争后应用程序工作台控制台无法工作
显示代码是如何实现的。 – james