android gcm 推送通知只播放声音,不显示在顶部
android gcm push notification playing only sound, not displaying at top
收到来自 GCM 的消息后,我正在生成通知
/**
* Create and show a simple notification containing the received GCM message.
*
* @param message GCM message received.
*/
private void sendNotification(String message) {
Intent intent = new Intent(this, MyActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_action_chat)
.setContentTitle("GCM Message")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
生成了通知,播放了声音,但没有显示在屏幕顶部。通知显示在快速 settings/notifications 下拉菜单中,但在我生成它时,它没有显示在屏幕顶部,只有声音。
我想在生成它时在屏幕顶部显示它。我该怎么做?
这是来自 android lollipop 的提示通知,您可以在此处查看如何显示通知 http://developer.android.com/guide/topics/ui/notifiers/notifications.html 对于提示,您必须按以下方式设置通知优先级
.setPriority(Notification.PRIORITY_HIGH)
编辑 11 月 17 日
Notification.PRIORITY_HIGH 在 API 级别 26 中被弃用。请改用 IMPORTANCE_HIGH。
就我而言,我必须这样做
.setSmallIcon(R.drawable.my_icon)
收到来自 GCM 的消息后,我正在生成通知
/**
* Create and show a simple notification containing the received GCM message.
*
* @param message GCM message received.
*/
private void sendNotification(String message) {
Intent intent = new Intent(this, MyActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_action_chat)
.setContentTitle("GCM Message")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
生成了通知,播放了声音,但没有显示在屏幕顶部。通知显示在快速 settings/notifications 下拉菜单中,但在我生成它时,它没有显示在屏幕顶部,只有声音。
我想在生成它时在屏幕顶部显示它。我该怎么做?
这是来自 android lollipop 的提示通知,您可以在此处查看如何显示通知 http://developer.android.com/guide/topics/ui/notifiers/notifications.html 对于提示,您必须按以下方式设置通知优先级
.setPriority(Notification.PRIORITY_HIGH)
编辑 11 月 17 日
Notification.PRIORITY_HIGH 在 API 级别 26 中被弃用。请改用 IMPORTANCE_HIGH。
就我而言,我必须这样做
.setSmallIcon(R.drawable.my_icon)