我试图在Android 5.0及更高版本上显示Notification内容作为弹出窗口,但我的编码此功能在Android状态栏上只显示小图标,我必须下拉状态栏布局以显示收到的通知'内容
public static void createNotification(Context context, Class activity, String title, String subject) {
Intent intent = new Intent(context, activity);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_CLEAR_TOP);
Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
R.drawable.dollar);
Notification notify = new NotificationCompat.Builder(context)
.setAutoCancel(true)
.setContentTitle(title)
.setContentText(subject)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(icon)
.setPriority(0)
.setLights(Color.BLUE, 500, 500)
.setContentIntent(pendingIntent)
.build();
notify.flags |= Notification.FLAG_AUTO_CANCEL;
NOTIFICATIONMANAGER = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
NOTIFICATIONMANAGER.notify(159753456, notify);
}
答案 0 :(得分:2)
您需要将优先级设置为高或最高,以便在支持它的Android版本上触发抬头通知:
Notification notify = new NotificationCompat.Builder(context)
// ...
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE)
.build();
正如官方Notification documentation所述,通知还需要振动或铃声来制作提醒通知:
通知具有高优先级并使用铃声或振动
有关提前通知的详情,请参阅this question。