Android常用的intentaction汇总
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Android常⽤的intentaction汇总
本⽂总结讲述了Android常⽤的intent action功能。
分享给⼤家供⼤家参考,具体如下:
Android基本的设计理念是⿎励减少组件间的耦合,因此Android提供了Intent (意图) ,Intent提供了⼀种通⽤的消息系统,它允许在你的应⽤程序与其它的应⽤程序间传递Intent来执⾏动作和产⽣事件。
Intent作为联系各Activity之间的纽带,其作⽤并不仅仅只限于简单的数据传递。
通过其⾃带的属性,其实可以⽅便的完成很多较为复杂的操作。
例如直接调⽤拨号功能、处理接收短信,诸如此类,都可以通过设置Intent属性来完成。
Intent主要有以下四个重要属性,它们分别为:
Action:Action属性的值为⼀个字符串,它代表了系统中已经定义了⼀系列常⽤的动作。
通过setAction()⽅法或在清单⽂件AndroidManifest.xml中设置。
标识Activity为⼀个程序开始的⽰例代码(AndroidManifest.xml进⾏配置)如下:
<span style="font-size:16px;">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="UNCHER" />
</intent-filter>
</span>
Data:Data通常是URI格式定义的操作数据。
例如:tel:// 。
通过setData()⽅法设置。
Category:Category属性⽤于指定当前动作(Action)被执⾏的环境。
通过addCategory()⽅法或在清单⽂件AndroidManifest.xml中设置。
默认为:CATEGORY_DEFAULT。
Extras:Extras属性主要⽤于传递⽬标组件所需要的额外的数据。
通过putExtras()⽅法设置。
在本⽂中,主要介绍常见action的使⽤,Action描述Intent所触发动作名字的字符串,对于BroadcastIntent来说,Action指被⼴播出去的动作。
理论上Action可以为任何字符串,⽽与Android系统应⽤有关的Action字符串以静态字符串常量的形式定义在了Intent类中。
Action中包含很多种,例如呼⼊,呼出电话,⽼师上课讲的接受短信等等,下⾯谨对常见的与系统有关的action 进⾏整理:
1. Intent.ACTION_MAIN
String: android.intent.action.MAIN
标识Activity为⼀个程序的开始。
2. Intent.Action_CALL
Stirng: android.intent.action.CALL
呼叫指定的电话号码。
Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:10086");
startActivity(intent);
3. Intent.ACTION_POWER_CONNECTED;
插上外部电源时发出的⼴播
4 Intent.ACTION_POWER_DISCONNECTED;
已断开外部电源连接时发出的⼴播
5.Intent.Action.DIAL
String: action.intent.action.DIAL
调⽤拨号⾯板
Intent intent=new Intent();
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:10086");
startActivity(intent);
6.Intent.Action.ALL_APPS
String: andriod.intent.action.ALL_APPS
列出所有的应⽤。
7.Intent.ACTION_ANSWER
Stirng:android.intent.action.ANSWER
处理呼⼊的电话。
8 .Intent.ACTION_BUG_REPORT
String: android.intent.action.BUG_REPORT
显⽰Dug报告。
9. Intent.Action_CALL_BUTTON
String: android.action.intent.CALL_BUTTON.
相当于按“拨号”键。
Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
startActivity(intent);
10. Telephony.SMS_RECEIVED
String: android.provider.Telephony.SMS_RECEIVED
接收短信的action
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<data android:host="localhost"/>
</intent-filter>
11. Intent.ACTION_GET_CONTENT
String: android.intent.action.GET_CONTENT
允许⽤户选择特殊种类的数据,并返回(特殊种类的数据:照⼀张相⽚或录⼀段⾳)12. Intent.ACTION_BATTERY_LOW;
String: android.intent.action.BATTERY_LOW
表⽰电池电量低
13. Intent.ACTION_SEND
String: android.intent.action.Send
发送邮件的action
14. Intent.ACTION_CALL_PRIVILEGED
String:android.intent.action.CALL_PRIVILEGED
调⽤skype的action
Intent intent = newIntent("android.intent.action.CALL_PRIVILEGED");
intent.setClassName("com.skype.raider",
"com.skype.raider.Main");
intent.setData(Uri.parse("tel:" + phone));
startActivity(intent);
15. Intent.ACTION_CLOSE_SYSTEM_DIALOGS
当屏幕超时进⾏锁屏时,当⽤户按下电源按钮,长按或短按(不管有没跳出话框),进⾏锁屏时,android系统都会⼴播此Action消息以上是对常见的action进⾏总结,action其实有很多,如果要使⽤上⽂没有列举到的,google即可。
更多关于Android相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》、《》、《》及《》希望本⽂所述对⼤家Android程序设计有所帮助。