Android通知刷卡删除禁用 [英] Android notification swipe delete disabling

查看:68
本文介绍了Android通知刷卡删除禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从android的通知列表中禁用android通知的滑动删除功能.请帮助我.

Is it possible to disable the swipe delete feature of an android notification from the notifications list in android. Please help me.

谢谢.

推荐答案

尝试此代码

builder.setOngoing(true); // Cant cancel your notification (except notificationManager.cancel(); )

在Notifcation Builder中的代码上方.

public void DisplayNotification() {

// Use NotificationCompat.Builder to set up our notification.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

//icon appears in device notification bar and right hand corner of notification
builder.setSmallIcon(R.drawable.ic_stat_notification);

// This intent is fired when notification is clicked
Intent tapIntent = new Intent(CurrentActivity.this, SecondActivity.class);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, tapIntent, 0);

// Set the intent that will fire when the user taps the notification.
builder.setContentIntent(pendingIntent);

builder.setOngoing(true); // Cant cancel your notification (except NotificationManger.cancel(); )

// Content title, which appears in large type at the top of the notification
builder.setContentTitle("Notifications Title");

// Content text, which appears in smaller text below the title
builder.setContentText("Your notification content here.");

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

// Will display the notification in the notification bar
notificationManager.notify(NOTIFICATION_ID, builder.build());
}

取消通知

public void cancelNotification() {
        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.cancel(NOTIFICATION_ID); // Notification ID to cancel
    }

快乐编码:)

这篇关于Android通知刷卡删除禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆