android中notification通知及自定义notification
2013-08-10 21:15
405 查看
// (写的顺序2) 1.创建通知对象 // 有通知的图标R.drawable.ic_launcher Notification notification = new Notification(R.drawable.ic_launcher, "通知1", System.currentTimeMillis());//当前时间 notification.flags = Notification.FLAG_AUTO_CANCEL;//自动取消通知(点击完) // (4) 2.点击事件关联的Activity //跳转到SecondActivity页面 Intent intent = new Intent(MainActivity.this, SecondActivity.class); PendingIntent contentIntent = PendingIntent. getActivity(MainActivity.this, 0, intent, 0); // 3.设置通知的标题和内容 // notification设置一个事件处理 notification.setLatestEventInfo(MainActivity.this, "title", "message", contentIntent); // (1) 4.发送通知 //得到通知管理器 // NotificationManager notificationManager = (NotificationManager) // getSystemService(Context.NOTIFICATION_SERVICE); //用通知管理器发通知 notificationManager.notify(1234, notification);
// notificationManager.cancel(1234);//手动清除通知
自定义notification及进度条更新的方法:
@Override public void onClick(View v) { sendNotifi(); for (int i = 1; i <= 10; i++) { try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } updateNotifi(i); } finishNotifi(); } private void finishNotifi() { notification = new Notification(R.drawable.ic_launcher, "下载完成", System.currentTimeMillis()); //设置通知的声音 notification.flags |= Notification.DEFAULT_SOUND; Intent intent = new Intent(); notification.contentIntent = PendingIntent.getActivity(this, 0, intent, 0); //使用自定义的布局 notification.contentView = new RemoteViews(getPackageName(), R.layout.notify); notification.contentView.setTextViewText(R.id.textView1, "进度100%"); notification.contentView.setProgressBar(R.id.progressBar1, 10, 10, false); mNotifimgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotifimgr.notify(1234, notification); } private void updateNotifi(int i) { notification.contentView.setTextViewText(R.id.textView1, "进度"); notification.contentView.setProgressBar(R.id.progressBar1, 10, i, false); mNotifimgr.notify(1234,notification); } private void sendNotifi() { notification = new Notification(R.drawable.ic_launcher, "准备升级", System.currentTimeMillis()); //设置通知的声音 notification.flags |= Notification.DEFAULT_SOUND; Intent intent = new Intent(); notification.contentIntent = PendingIntent.getActivity(this, 0, intent, 0); notification.contentView = new RemoteViews(getPackageName(), R.layout.notify); mNotifimgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotifimgr.notify(1234, notification); }
本文出自 “wangcuijing” 博客,请务必保留此出处http://wangcuijing.blog.51cto.com/7233352/1269485
相关文章推荐
- android 自定义通知布局Notification,点击Notification导航切换回原Activity
- Android种使用Notification实现通知管理以及自定义通知栏(Notification示例四)
- Android Notification自定义通知样式你要知道的事
- android自定义通知,android自定义Notification
- 使用 Android 自定义通知Notification时遇到的问题
- Android自定义通知布局Notification,点击Notification导航切换回原Activity
- Android 自定义Notification消息通知样式并实现与Activity简单交互
- Android种使用Notification实现通知管理以及自定义通知栏(Notification示例四)
- Android Notification自定义通知样式你要知道的事
- Android通知栏实现APP下载更新(DownloadManager和自定义Notification2种方式实现)
- Android中通知栏Notification详解以及自定义Notification
- Android 使用Notification自定义通知栏显示
- Android 通知栏Notification,NotificationManager,RemoteViews使用流程,自定义通知栏样式简介
- Android 自定义通知Notification 适配不同背景颜色
- 59 Android Notification 自定义通知
- Android Notification自定义通知样式你要知道的事
- Android通知栏实现APP下载更新(DownloadManager和自定义Notification2种方式实现)
- Android中的通知Notification介绍和自定义Notification
- Android自定义通知布局Notification,点击Notification导航切换回原Activity
- Android自定义通知布局Notification,点击Notification导航切换回原Activity