Android基本的设计理念是鼓励减少组件间的耦合,因此Android提供了Intent (意图) ,Intent提供了一种通用的消息系统,它允许在你的应用程序与其它的应用程序间传递Intent来执行动作和产生事件。Intent作为联系各Activity之间的纽带,其作用并不仅仅只限于简单的数据传递。通过其自带的属性,其实可以方便的完成很多较为复杂的操作。例如直接调用拨号功能、处理接收短信,诸如此类,都可以通过设置Intent属性来完成。
Intent主要有以下四个重要属性,它们分别为:
Action:Action属性的值为一个字符串,它代表了系统中已经定义了一系列常用的动作。通过setAction()方法或在清单文件AndroidManifest.xml中设置。标识Activity为一个程序开始的示例代码(AndroidManifest.xml进行配置)如下:
-
<spanstyle="font-size:16px;"><intent-filter>
-
<actionandroid:name="android.intent.action.MAIN"/>
-
<categoryandroid:name="android.intent.category.LAUNCHER"/>
-
</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 Itent Action 小结
恢复已经停止的更新下载。 'android.server.checkin.FOTA_RESTART' 通过 OTA 下载并安装操作系统更新。 'android.server.checkin.FOTA_UPDATE' 用户按下了'Media Button'。...'android.intent.action.PACKAGE_ADDED'
接收系统的时间流逝的广播,屏幕开启关闭的广播,电量改变的广播。这些广播在清单文件里注册时,看不到效果。在这个例子中通过在一个服务里面用代码注册的方式,成功接收了这些广播。
Android 广播大全 Intent Action 事件.
android intent和intent action大全
主要为大家详细介绍了Android利用Intent启动和关闭Activity的相关操作,感兴趣的小伙伴们可以参考一下
Android 广播事件 Intent Action 大全
android.intent.action.PACKAGE_REMOVED和android.intent.action.PACKAGE_ADDED 可以监听别的应用被安装卸载,但不能监听自己被卸载啊。 监听自己被卸载通过前辈们探索发现,只能通过监听系统卸载log如:act=...
android intent和intent action大全.doc
android Action call 拨打电话 Intent.ACTION.CALL
Android Intent Action
Android Intent Action 大全.doc
主要介绍了Android常用的intent action功能与用法,分析了intent的原理以及action属性常用动作名称、作用与使用方法,需要的朋友可以参考下
Intent在Android应用开发中,占有很大的分量,关于Intent在Android中的作用在网络上已经有很多资料了,这里不再累赘,本人喜欢直来直去。在网上看到很多关于Intent的资料,说那么多,你也许还是一头雾水,到底如何...
android用于打开各种文件的intent
Android 屏幕唤醒 + 屏幕解锁 + 开机服务监听(android.intent.action.BOOT_COMPLET)添加权限:{//开机监听<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/><uses-permission android...
主要介绍了Android利用Intent.ACTION_SEND进行分享,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Intent intent = new Intent("android.intent.action.SILENT_PACKAGE_INSTALL"); intent.putExtra("silent_install_file", "/sdcard/Helloworld.apk"); intent.putExtra("silent_install_auto_start", true);//...
用Action跳转,用类名跳转,Intent的用法 1. 从google搜索内容 2. 浏览网页 3. 显示地图 4. 路径规划 5. 拨打电话 6. 发送短信 等等