Android: 点击后隐藏我的提醒通知
Android: Hide my reminder notification when it has been clicked
我的 android 应用程序中有一个通知系统,当通知时间到达时,我的通知显示在通知栏中,当用户点击它时,我的应用程序打开,但通知中仍然显示通知酒吧。如何在用户点击通知栏时隐藏通知?
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Calendar now = GregorianCalendar.getInstance();
Bundle bund = intent.getExtras();
String text = bund.getString("name", "");
Notification.Builder mBuilder =
new Notification.Builder(context)
.setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle( text)
.setContentText("text");
Toast.makeText(context,"ok", Toast.LENGTH_LONG).show();
Intent resultIntent = new Intent(context, Main.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(Main.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
// }
}
}
你试试吗?
mBuilder.setAutoCancel(true);
我的 android 应用程序中有一个通知系统,当通知时间到达时,我的通知显示在通知栏中,当用户点击它时,我的应用程序打开,但通知中仍然显示通知酒吧。如何在用户点击通知栏时隐藏通知?
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Calendar now = GregorianCalendar.getInstance();
Bundle bund = intent.getExtras();
String text = bund.getString("name", "");
Notification.Builder mBuilder =
new Notification.Builder(context)
.setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle( text)
.setContentText("text");
Toast.makeText(context,"ok", Toast.LENGTH_LONG).show();
Intent resultIntent = new Intent(context, Main.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(Main.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
// }
}
}
你试试吗?
mBuilder.setAutoCancel(true);