Flo*_*Flo 127 notifications android
如果我想在通知栏中显示通知问题.虽然我将通知标志设置为通知,Notification.DEFAULT_LIGHTS & Notification.FLAG_AUTO_CANCEL但在单击后不会消失.我有什么想法我做错了吗?
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.icon;
CharSequence tickerText = "Ticker Text";
long time = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, time);
notification.flags = Notification.DEFAULT_LIGHTS & Notification.FLAG_AUTO_CANCEL;
Context context = getApplicationContext();
CharSequence contentTitle = "Title";
CharSequence contentText = "Text";
Intent notificationIntent = new Intent(this, SilentFlipConfiguration.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(1,notification);
Run Code Online (Sandbox Code Playgroud)
Kam*_*nek 292
同时建立Notification由NotificationBuilder可以使用notificationBuilder.setAutoCancel(true);.
syn*_*nic 129
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL
Run Code Online (Sandbox Code Playgroud)
从文档:
如果在用户单击通知时应取消通知,则应将位置按位或编入标志字段
Dar*_*rcy 27
// Uses the default lighting scheme
notification.defaults |= Notification.DEFAULT_LIGHTS;
// Will show lights and make the notification disappear when the presses it
notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
Run Code Online (Sandbox Code Playgroud)
art*_*s90 13
2016状态:你可以使用mBuilder.setAutoCancel(true).
资料来源:https://developer.android.com/reference/android/app/Notification.Builder.html