gpt4 book ai didi

android - 应用未打开时显示抬头通知

转载 作者:行者123 更新时间:2023-12-02 01:08:35 26 4
gpt4 key购买 nike

我使用 fcm 并且抬头通知将在应用程序打开时显示,但在应用程序未打开或被终止时不显示。
应用未打开时如何处理提醒通知?

最佳答案

医生说:

With Android 5.0 (API level 21), notifications can appear in a small floating window (also called a heads-up notification) when the device is active (that is, the device is unlocked and its screen is on). These notifications appear similar to the compact form of your notification, except that the heads-up notification also shows action buttons. Users can act on, or dismiss, a heads-up notification without leaving the current app.



根据 Doc,如果您想要提醒通知,您必须创建自己的通知,如下所示:
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
if (Build.VERSION.SDK_INT >= 21) notificationBuilder.setVibrate(new long[0]);

不要滥用抬头通知。见 here何时使用提醒通知:

MAX: For critical and urgent notifications that alert the user to a condition that is time-critical or needs to be resolved before they can continue with a particular task.

HIGH: Primarily for important communication, such as messages or chat events with content that is particularly interesting for the user. High-priority notifications trigger the heads-up notification display.



来自 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.
}

关于android - 应用未打开时显示抬头通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46396991/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com