• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Patata
http://weibo.com/totome
博客园    首页    新随笔    联系   管理    订阅  订阅
PendingIntent 结合Notification的使用

是封装了一个 Intent 以及 Intent 接收者的描述对象,它是一种延迟执行的 Intent, 该 PendingIntent 不会立即被处理,而是交付给其他应用程序,等待一个事件的触发后被送出
PendingIntent  的构造
getActivity(Context  context, int  reqCode, Intent, int  flag)
getBroadcast(Context  context, int  reqCode, Intent, int  flag)
getService(Context  context, int  reqCode, Intent, int  flag)
PendingIntent 的发送
send  执行 PendingIntent 指定的操作
PendingIntent 的取消
cancel()   只能被 PendingIntent 创造者进行调用

 

 1 //声明通知(消息)管理器
 2 NotificationManager nfcm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
 3 //点击通知时跳转到另一个 Activity,查看通知的详细内容
 4 Intent intent = new Intent(this, Notification_Message.class);
 5 //构建 Notification 对象
 6 Notification nfc = new Notification();
 7 
 8 strTitle = "通知栏按钮4标题";
 9 strContent = "通知栏按钮4内容";
10 //设置 PendingIntent
11 //intent 对象中要携带的数据必须在 PendingIntent.getActivity 方法前设置好,否则会取不到 intent 对象中的数据
12 intent.putExtra("title", title);
13 intent.putExtra("content", content);
14 //设置点击通知时显示内容的类
15 PendingIntent pIntent = PendingIntent.getActivity(Notification_Demo1.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
16 
17 //设置通知在状态栏显示的图标
18 nfc.icon = R.drawable.icon;
19 //当我们点击通知时显示的内容
20 nfc.tickerText = "按钮4的通知内容";
21 //通知时既震动又屏幕发亮还有默认的声音
22 nfc.defaults = Notification.DEFAULT_ALL;
23 //设置通知显示的参数(拉下状态栏后显示的内容)
24 nfc.setLatestEventInfo(Notification_Demo1.this, strTitle, strContent, pIntent);
25 //执行这个通知
26 nfcm.notify(0, nfc);

 

posted on 2012-08-31 10:00  Blacksky  阅读(592)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3