PendingIntent的使用
来源:互联网 发布:淘宝卖ps软件犯法吗 编辑:程序博客网 时间:2024/05/22 13:55
参看原文:http://blog.csdn.net/zeng622peng/article/details/6180190
http://blog.csdn.net/yuzhiboyi/article/details/8484771
先看例子
<span style="font-size:18px;">private void showNotify(){ Notification notice=new Notification(); notice.icon=R.drawable.icon; notice.tickerText="您有一条新的信息"; notice.defaults=Notification.DEFAULT_SOUND; notice.when=10L; // 100 毫秒延迟后,震动 250 毫秒,暂停 100 毫秒后,再震动 500 毫秒 //notice.vibrate = new long[] { 100, 250, 100, 500 };出错? //notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, null, 0)); notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, new Intent(this,otherAct ivity.class,null);<span style="color:#cc0000;">//即将跳转页面,还没跳转,这时Intent已经交给了NotigicationManager处理了。</span></span><pre name="code" class="java"><span style="font-size: 18px;"> </span><span style="font-family: Arial, Helvetica, sans-serif;">//获取系统通知服务</span>NotificationManager manager=(NotificationManager)getSystemService(this.NOTIFICATION_SERVICE); manager.notify(0,notice); } 例子中Intent什么时候开始被处理呢?应该在manager.notify(0,notice)中被处理,此时manager通过调用传进来的notice中的PendingIntent的send()方法。PendingIntent.send(){
方法中可以做这样处理,源程序Context.startActivity(Intent); }
什么时候调用就要看NotificationManager了。
发送短信的例子:
private final static String SEND_ACTION = "send";private final static String DELIVERED_ACTION = "delivered";private void sendSms(String receiver, String text) { SmsManager s = SmsManager.getDefault(); PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SEND_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); // 发送完成 registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "Send Success!", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Send Failed because generic failure cause.", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "Send Failed because service is currently unavailable.", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Send Failed because no pdu provided.", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Send Failed because radio was explicitly turned off.", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getBaseContext(), "Send Failed.", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(SEND_ACTION)); // 对方接受完成 registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "Delivered Success!", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getBaseContext(), "Delivered Failed!", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(DELIVERED_ACTION)); // 发送短信,sentPI和deliveredPI将分别在短信发送成功和对方接受成功时被广播 s.sendTextMessage(receiver, null, text, sentPI, deliveredPI);}
0 0
- PendingIntent android.app.PendingIntent.getActivity的使用
- PendingIntent的使用
- PendingIntent的使用
- PendingIntent的使用
- Android PendingIntent的使用
- PendingIntent的使用
- android之PendingIntent的使用
- Intent和PendingIntent的使用和区别
- 发送短信中,PendingIntent.getBroadcase的使用
- 关于onNewIntent的使用&PendingIntent flag赋值
- Notification和PendingIntent的结合使用
- AlarmMananger及PendingIntent的首次使用
- Android PendingIntent使用的特殊情况
- Android中PendingIntent的简单使用
- Android开发之PendingIntent的使用
- android之PendingIntent使用
- PendingIntent使用注意事项
- PendingIntent使用填坑记
- JavaScript学习--Item14 使用prototype的几点注意事项
- nRF51822外部中断学习总结
- 列表控件RecyclerView的使用
- iOS 数据库篇7—FMDB简单介绍
- inner join 和where哪个效率更高
- PendingIntent的使用
- JS获取URL参数
- mysql 二进制日志清理
- 链接 <a> 的CSS伪类不起作用
- MySQL优化
- 索引
- Linux连接MySQL出现1045错误 解决方法
- 怎么用几何画板解方程
- ajax处理json数据