Android28--Android之Android的通知(Notification)使用详解
来源:互联网 发布:encode url php 编辑:程序博客网 时间:2024/06/05 03:48
1. 有关Notification的详解
http://www.2cto.com/kf/201502/374946.html
2. 案例
附上两个例子,,一个是开启一个通知, 另一个是开启一个服务,,甚至是主要代码:
public void btnBormalNotify(View view) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // title, text, smallIcon 必须设置 builder.setContentTitle("通知") .setContentText("内容") .setSmallIcon(R.mipmap.ic_launcher); // // 声音可以自定义 // Uri.fromFile() // builder.setSound(); builder.setDefaults(Notification.DEFAULT_ALL); Intent intent = new Intent(this, NewsActivity.class); intent.putExtra("uri", "www.baidu.com"); // !!!使用通知的PendingIntent时,必须设置 Intent 的 FLAG, 针对于Activity intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pi); Notification build = builder.build(); NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this); managerCompat.notify(998, build); } public void btnReceiver(View view) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle("通知") .setContentText("内容") .setSmallIcon(R.mipmap.ic_launcher); builder.setDefaults(Notification.DEFAULT_ALL); // !! 可以在通知中添加按钮点击操作 Intent intent = new Intent("com.xiaohong.ACTION_PLAY"); // 和在Intent里面设置Action同样的作用 //intent.setClassName(this, MyReceiver.class.getName()); // getBroadcast 内部会执行 sendBroadcast PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(android.R.drawable.ic_media_play, "播放", piPlay); Notification build = builder.build(); NotificationManagerCompat from = NotificationManagerCompat.from(this); from.notify(999, build); }
0 0
- Android28--Android之Android的通知(Notification)使用详解
- Android的通知(Notification)使用详解
- Android的通知(Notification)使用详解
- Android的通知(Notification)使用详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android--通知之Notification详解
- Android--通知之Notification详解
- Android之Notification通知详解
- Android通知(Notification)使用详解
- Linux内存管理之mmap详解
- java中堆区和栈区的理解
- NOIP水题(1)——信息传递
- 安卓实现水波纹动画效果
- 人格魅力的六法宝
- Android28--Android之Android的通知(Notification)使用详解
- Handler的用法介绍
- 图像概念
- (多态)Java向上转型之后调用子类的同名变量/方法的问题
- Map中的键值对进行遍历
- 高性能mysql读书笔记
- hdu 2098 分拆素数和
- 第四周--建设单链表算法库
- Cesium学习(4)--使用gdal2srtmtiles-demo.py生成高程数据