医生说:
在 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.
}