我使用fcm和擡頭通知將顯示應用程序何時打開,但未顯示應用程序未打開或已關閉時是否顯示。 如何處理應用程序未打開時的通知?當應用程序未打開時顯示擡頭通知
回答
文件說:
藉助Android 5.0(API級21),通知可以在一個小 浮動窗口(也稱爲擡頭通知)時,該設備 是活性出現(即,設備已解鎖並且其屏幕處於打開狀態)。 這些通知與您的 通知的緊湊形式類似,但擡頭通知也顯示動作 按鈕。用戶可以在沒有 而離開當前應用程序的情況下采取行動或解除提醒通知。
按照Doc,如果你想單挑,你必須創建自己的如下通知:
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
if (Build.VERSION.SDK_INT >= 21) notificationBuilder.setVibrate(new long[0]);
不要濫用擡頭通知。見here何時使用擡頭通知:
MAX:對於提醒用戶一個 條件是時間緊急和需要解決才 可以與特定的持續重大而緊迫的通知任務。
HIGH:主要用於重要的溝通,如消息或聊天 內容對用戶特別感興趣的事件。 高優先級通知觸發擡頭通知顯示。
附加說明從HERE
更新:
要覆蓋GCM監聽服務:
<service android:name=".MyGcmListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
FCM是:
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
然後重寫方法:
GCM:
public class MyGcmListenerService
extends GcmListenerService {
@Override
public void onMessageReceived(String from, Bundle data) {
... create your heads-up notification here.
}
FCM:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
... create your heads-up notification here.
}
不能在評論後,所以在這兒呢。嘗試一下,我已經測試過:
private void test() {
Intent intent;
intent = new Intent(this, SplashScreenActivity.class);
Bundle bundle = new Bundle();
bundle.putBoolean("isDisplayAlert", true);
bundle.putString("NOTIFICATION_DATA", "data");
intent.putExtras(bundle);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),
new Random().nextInt(), intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_location)
.setContentTitle("Title")
.setContentText("Body")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setOnlyAlertOnce(true)
.setFullScreenIntent(pendingIntent, true);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
notificationBuilder.setVibrate(new long[0]);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
我通過控制檯firebase進行測試並拍攝到我的手機或emu。它同樣發生了擡頭通知不顯示,但只顯示正常通知。 –
顯示您的代碼,完整的流程。 – james
https://imgur.com/a/rHc72我的代碼和清單https://imgur.com/a/3odHb –
- 1. 本地通知當應用程序打開時未顯示
- 2. 通知Android:當應用程序打開時不顯示通知?
- 3. Android顯示應用程序未打開時的通知?
- 4. 當應用程序打開時不顯示FCM通知
- 5. 如何顯示擡頭通知android
- 6. 通知到達時不會顯示擡頭通知
- 7. 爲什麼擡頭通知在應用未運行時不顯示
- 8. 防止在應用程序打開時顯示通知
- 9. Android - 如何停止顯示通知時打開應用程序
- 10. FCM擡頭通知
- 11. 當應用程序在後臺顯示通知時不顯示
- 12. 當應用程序打開時,推送通知不起作用
- 13. OpenGL擡頭顯示
- 14. 打開應用程序時更新應用程序通知
- 15. 應用程序打開或背景(顯示通知與否)
- 16. 當應用程序打開時停止推送通知振動
- 17. 當應用程序退出時顯示遠程通知的uiviewcontroller
- 18. 當我收到通知時,我的應用程序將在後臺打開,只顯示通知並不打開應用程序?
- 19. 當應用程序打開時未收到Android上的推送通知
- 20. 當應用程序打開時未收到Firebase消息Android通知
- 21. 當主應用程序未運行時顯示通知的後臺進程
- 22. 如何顯示應用程序未運行時的通知
- 23. Android:當應用程序關閉時顯示通知
- 24. 當應用程序在後臺時不顯示推送通知
- 25. 從通知中打開應用程序
- 26. GCM - 從通知打開應用程序?
- 27. modalViewController當應用程序打開時顯示
- 28. 當重新打開應用程序時警報不顯示
- 29. UIAlertView中顯示當應用程序加載時,打開
- 30. 從通知中打開應用程序時顯示特定選項卡
到目爲止我知道,當消息被收到並且應用程序在後臺時,FCM會自動顯示通知。 –
是正常通知顯示,但擡頭通知不顯示。 –