Java代码
  1. Notificationn= new Notification(R.drawable.face_1, "Service启动" ,System.currentTimeMillis());
  2. PendingIntentcontentIntent=PendingIntent.getActivity(this , 0 , new Intent( this ,TServiceHolder. class ), 0 );
  3. n.setLatestEventInfo(this , "任务标题" , "任务内容" ,contentIntent);
  4. nManager.notify(NOTIFICATION_ID,n);//任务栏启动
Notification n = new Notification(R.drawable.face_1, "Service启动", System.currentTimeMillis());PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TServiceHolder.class), 0);n.setLatestEventInfo(this, "任务标题", "任务内容", contentIntent);nManager.notify(NOTIFICATION_ID, n); // 任务栏启动

PendingIntent和Intent的区别:An Intent is something that is used right now; a PendingIntent is something that may create an Intent in the future. You will use a PendingIntent with Notifications, AlarmManager, etc.

1. GSM网络中android发送短信示例

(1)代码节选

Java代码
  1. Stringmsg= "你好,美女" ;
  2. Stringnumber="135****6784" ;
  3. SmsManagersms=SmsManager.getDefault();
  4. PendingIntentpi=PendingIntent.getBroadcast(SmsActivity.this , 0 , new Intent(...), 0 );
  5. sms.sendTextMessage(number,null ,msg,pi, null );
  6. Toast.makeText(SmsActivity.this , "发送成功" ,Toast.LENGHT_LONG).show();
String msg ="你好,美女";String number = "135****6784";SmsManager sms = SmsManager.getDefault();PendingIntent pi = PendingIntent.getBroadcast(SmsActivity.this,0,new Intent(...),0);sms.sendTextMessage(number, null, msg, pi, null);Toast.makeText(SmsActivity.this,"发送成功",Toast.LENGHT_LONG).show();

(2)代码解释

PendingIntent就是一个Intent的描述,我们可以把这个描述交给别的程序,别的程序根据这个描述在后面的别的时间做你安排做的事情 (By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself,就相当于PendingIntent代表了Intent)。本例中别的程序就是发送短信的程序,短信发送成功后要把intent广播出 去 。
函数SmsManager.sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)中参数解释:
1)PendingIntent sentIntent:当短信发出时,成功的话sendIntent会把其内部的描述的intent广播出去,否则产生错误代码并通过 android.app.PendingIntent.OnFinished进行回调,这个参数最好不为空,否则会存在资源浪费的潜在问题;
2)PendingIntent deliveryIntent:是当消息已经传递给收信人后所进行的PendingIntent广播。
查看PendingIntent 类可以看到许多的Send函数,就是PendingIntent在进行被赋予的相关的操作。

更多相关文章

  1. android 启动延迟加载画面
  2. Android点击通知栏消息,仅打开App,不跳转到具体Activity
  3. android webview ZoomButtonsController 导致android.view.Windo
  4. Android延时执行的几种方法
  5. Android实现倒计时启动功能的实现
  6. 2011.07.12——— android Foreground service
  7. Android(安卓)studio 启动模拟器报错-Turn off Hyper-V
  8. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Fedora镜像
  9. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像

随机推荐

  1. android + javascript 相互通信实例分析
  2. android去掉titlebar
  3. 定义风格
  4. Android使用插件SimpleCropView
  5. android 尺寸单位介绍(dp,sp,px)
  6. rk3288 Android 7.1 rt5640 调试
  7. Android 系统Action大全
  8. [小技巧]Android 圆形progressbar的旋转
  9. android之自定义ViewGroup和自动换行的布
  10. PNG资源导出脚本