android - 我怎样才能清除这个通知

标签 android notifications android-notifications

函数

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/

相关文章:

Objective-C Mac OS X 分布式通知 iTunes

android - 强制通知分组?

android - 如何判断通知栏是否在android中被拉下

android - 在真实设备上振动多次以在android中通知(接近警报)

android - 从状态栏中的扩展通知中获取文本?

android - 目标 API 级别 29 的 AndroidQ 不需要 WRITE_EXTERNAL_STORAGE 权限,它是否会破坏安全性?

java - 如何将自定义 getView 绑定(bind)到 ListView 适配器?

android - UV 和顶点的单独索引

android.database.sqlite.SQLITeException : no such table: admin while compiling: INSERT INTO . ..等

java - Android 通知未启动 Activity