函数
private void startService() {
if (!onForeground) {
Log.d(Constants.TAG, "RecordService startService");
Intent intent = new Intent(this, MainActivity.class);
// intent.setAction(Intent.ACTION_VIEW);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent pendingIntent = PendingIntent.getActivity(
getBaseContext(), 0, intent, 0);
Notification notification = new NotificationCompat.Builder(
getBaseContext())
.setContentTitle(
this.getString(R.string.notification_title))
.setTicker(this.getString(R.string.notification_ticker))
.setContentText(this.getString(R.string.notification_text))
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pendingIntent).setOngoing(false)
.getNotification();
notification.flags = Notification.FLAG_AUTO_CANCEL;
startForeground(1337, notification);
onForeground = false;
}
}
当我想从通知中删除它时,我应该怎么做才能取消通知..我是 android 的新手所以请帮助我
最佳答案
NotificationCompat.Builder setAutoCancel (boolean autoCancel) Setting this flag will make it so the notification is automatically canceled when the user clicks it in the panel.
您可以找到有关如何创建通知的更多信息 here .
关于android - 我怎样才能清除这个通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38042541/