Android:通知随记1
2015-12-14 22:27
471 查看
1)通知的分类
普通通知,大视图通知,进度通知,自定通知
2)获取通知管理者
NotificationManager notificationMananger = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
3)创建通知公共的一些参数:
公共的一些参数: // 创建视图Builder对象
NotificationCompat.Builder builder = null; builder = new NotificationCompat.Builder(this);// 创建通知Builder对象 // 通知的图片 builder.setSmallIcon(R.drawable.qq); // 设置自动消失 builder.setAutoCancel(true); // 获取声音的Uri Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/" + R.raw.eatthings1); // 默认的声音 // builder.setDefaults(Notification.DEFAULT_VIBRATE | // Notification.DEFAULT_SOUND); // 设置自定义通知的声音 builder.setSound(sound); builder.setDefaults(Notification.DEFAULT_VIBRATE); // 获取PendingIntent Intent intent = new Intent(this, Activity00.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); // 设置未来的意图 builder.setContentIntent(pIntent); Notification notification = null;
4)普通通知
// 普通通知 // 设置标题 builder.setContentTitle("花千骨"); // 设置内容 builder.setContentText("我神的名义诅咒你(白子画):生生世世,不伤,不老,不死"); notification = builder.build(); notificationMananger.notify(0, notification);
5)大视图通知
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle( builder); style.setBigContentTitle("大视图通知");// 设置标题 for (int i = 0; i < datas.length; i++) { style.addLine(datas[i]);// 一行一行加到箱子 } // 创建通知对象 notification = builder.build(); // 短信管理者调用通知对象,进行通知 notificationMananger.notify(1, notification);
6)进度条通知
builder.setProgress(100, values[0], false);7)自定通知
// 创建远程的View // packageName:包名 RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.view_notification_remote); // 修改远程View remoteViews.setTextViewText(R.id.remote_tv, "中秋节快乐"); remoteViews .setImageViewResource(R.id.remote_image, R.drawable.sina); builder.setContent(remoteViews); notification = builder.build(); notificationMananger.notify(3, notification);
8)取消通知
notificationMananger.cancelAll();
cancel(id);
相关文章推荐
- Android:Sqlite 常见两个类SQLiteOpenHelper,SQLiteDatabase 随记
- Android内存优化(使用SparseArray和ArrayMap代替HashMap)
- Android:Fragment+ViewPager+FragmentPagerAdapter
- 【Android】在浏览器中打开url链接,打开Service,复习IntDef
- Android Studio 常用快捷键
- Android:FragmentTransaction的commit 和addToBackStack的方法随记
- Android 屏幕旋转 处理 AsyncTask 和 ProgressDialog 的最佳方案
- android volley通信框架解析
- android小技巧
- Android:菜单随记
- Android:Fragment 初步之旅 随记一
- Android学习笔记——SwipeRefreshLayout 官方下拉刷新控件介绍
- Android-JNI(1)-简介
- Android:Activity 相关的东西 随记一
- Android拓展系列(5)--CyanogenMod源码下载和编译(Android ROM定制基础篇)
- Android:ViewPager 随记一
- Android Xfermode 真实 实现全面、圆角图片
- Json数据格式介绍、使用Android自带类库完成Json生成与解析
- Android: ListView 性能调优二 随记
- Android自定义类似联系人列表的 快速索引控件