我怎样(如果可能的话)强制公开通知?就像来电提醒通知一样?
Intent intent = new Intent(context, ResultActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder b = new NotificationCompat.Builder(context);
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setTicker("Hearty365")
.setContentTitle("Default notification")
.setContentText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
//.setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
.setContentIntent(contentIntent)
.setContentInfo("Info")
.addAction(android.R.drawable.ic_media_pause, "Start", contentIntent)
.addAction(android.R.drawable.ic_dialog_alert, "Pause", contentIntent);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, b.build());
答案 0 :(得分:1)
答案 1 :(得分:0)
嗨@Dim只需要在Notification Builder中添加一行。
.setOngoing(true)
希望它能奏效。 :)