`
xuyuanshuaaa
  • 浏览: 389421 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

Intent

阅读更多
1   Intent是一种运行时绑定机制,能在程序运行的过程中链接两个不同的组件。Intent对象抽象的描述了要执行的操作,其描述的基本内容可以分为组件名称,Action,Data,Category,Extra(附加信息),Flag标志位。

2    Intent的解析
分为显示Intetn和隐式Intent,
显示通常用于应用程序内部传递消息,必然activity启动一个service,往往开发人员不知道别得应用程序的组件的名称所有多用于应用内部
隐式,Android系统使用IntentFilter来寻找与隐式Intent相关的对象。IntentFilter过滤器中包含系统中所有可能的待选组件,如果IntentFilter中的某一组件匹配隐式Intent请求的内容,那么android就会选择该组件作为隐式Intent的目标组件。

3   应用程序必须在androidManifest.xml中声明自己所含组件的过滤器。android的选择参考标准:Action,Data,Category
示例:
public void onClick(View b) {
String callee = phoneNumber.getText().toString();
if (PhoneNumberUtils.isGlobalPhoneNumber(callee))
{
Intent i = new Intent(Intent.ACTION_CALL, Uri.parse("tel://" + callee));
//参数必须采用uri的形式
//Intent.ACTION_CALL换为DIAL则首先进入系统自带的拨号系统程序
startActivity(i);
} else {
Toast.makeText(TinyDialer.this, R.string.notify_incorrect_phonenumber,
Toast.LENGTH_LONG).show();


<uses-permission android:name="android.permission.CALL_PHONE" />
}
}     
发送信息
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("sms://"));
sendIntent.putExtra("address", "123456789");
sendIntent.putExtra("sms_body", "foo bar");
startActivity(sendIntent);

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" /

除了我们在实例中包含的内容以外,复杂的电话或短信应用可以参考Android的相关包,它们分别是android.telephony和android.telephony.gsm。android.telephony包
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics