我已經實施了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