Android 通知栏点击取消
2015-11-12 14:54
381 查看
看了很多文章写了怎么取消通知栏的,自己试了就是取消不掉。后来尝试之后实现了,代码写错了。
错误的代码是:其实已经不是一个对象了。
推荐:/article/1970429.html
public class LoginSuccess extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.success_login); Toast.makeText(LoginSuccess.this, "登陆成功", 2000).show(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle("通知栏标题 ") .setContentText("通知内容") // .setContentIntent(getDefalutIntent(Notification.FLAG_AUTO_CANCEL))//点击意图 .setTicker("通知首次出现在通知栏,带上升动画效果的") .setWhen(System.currentTimeMillis())//通知产生的时间,会在通知信息里显示,一般是系统获取到的时间 .setPriority(Notification.PRIORITY_DEFAULT) .setAutoCancel(true)//用户点击就自动消失 .setOngoing(true)//ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接) .setDefaults(Notification.DEFAULT_VIBRATE)//向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合 //Notification.DEFAULT_ALL Notification.DEFAULT_SOUND 添加声音 // requires VIBRATE permission .setSmallIcon(R.drawable.taobao);//设置通知小ICON Notification notification = builder.build(); notification.flags = Notification.FLAG_AUTO_CANCEL; notificationManager.notify(100, notification); // notificationManager.cancel(100);//通知以后自动消失了 } }
错误的代码是:其实已经不是一个对象了。
Notification notification = builder.build(); notification.flags = Notification.FLAG_AUTO_CANCEL; notificationManager.notify(100, builder.build());
推荐:/article/1970429.html
相关文章推荐
- android编码的理解1
- 浅析Android的资源打包和安装后Apk文件的下落
- Android中drawableStart和drawableLeft的区别
- Android编程实现监听EditText变化的方法
- Android实现透明式状态栏
- SignalR在Xamarin Android中的使用
- The Perils of Loading Native Libraries on Android
- Android之如何使用javascript调用android代码
- Android使用KSOAP2调用WebService及正确导入jar包的问题(转)
- 如何在Android的ListView中构建CheckBox和RadioButton列表(支持单选和多选的投票项目示例)
- 问题记录:在打包APK的时候遇到的问题
- android 遗忘很久的android 渐变色
- Mac下android_sdk配置环境变量
- android 强制修改adb pull 文件的路径
- Android编程之消息机制实例分析
- Android Studio背景换图片跟一些比较好用插件的介绍
- Android Studio资源
- Android中的硬件加速
- Android 自定义长按事件
- Android 手势基础 GestureDetector和SimpleOnGestureListener的使用教程