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="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消息

18打开联系人列表           
  <1>                        Intent i = new Intent();             i.setAction(Intent.ACTION_GET_CONTENT);             i.setType("vnd.android.cursor.item/phone");    
        startActivityForResult(i, REQUEST_TEXT);         
     <2>              Uri uri = Uri.parse("content://contacts/people");              Intent it = new Intent(Intent.ACTION_PICK, uri);              startActivityForResult(it, REQUEST_TEXT);  

19 打开另一程序  Intent i = new Intent();    
         ComponentName cn = new ComponentName("com.yellowbook.android2",                      "com.yellowbook.android2.AndroidSearch");            
i.setComponent(cn);            
i.setAction("android.intent.action.MAIN");     
startActivityForResult(i, RESULT_OK);  

20.调用系统编辑添加联系人高版本SDK有效
  Intent it = new Intent(Intent.ACTION_INSERT_OR_EDIT);                  it.setType("vnd.android.cursor.item/contact");       
          // it.setType(Contacts.CONTENT_ITEM_TYPE);                  it.putExtra("name", "myName");                  it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY,  "organization");                  it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL, "email");                  it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,"homePhone");                  it.putExtra( android.provider.Contacts.Intents.Insert.SECONDARY_PHONE,                                  "mobilePhone");               
  it.putExtra(  android.provider.Contacts.Intents.Insert.TERTIARY_PHONE,                                  "workPhone");                  it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,"title");                  startActivity(it); 

21.调用系统编辑添加联系人全有效  Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);              intent.setType(People.CONTENT_ITEM_TYPE);              intent.putExtra(Contacts.Intents.Insert.NAME, "My Name");              intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");              intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE, Contacts.PhonesColumns.TYPE_MOBILE);              intent.putExtra(Contacts.Intents.Insert.EMAIL, "[email protected]");              intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE,                    Contacts.ContactMethodsColumns.TYPE_WORK);   
          startActivity(intent); 

22(更新)      //直接打电话出去     
  Uri uri = Uri.parse("tel:0800000123");   
    Intent it = new Intent(Intent.ACTION_CALL, uri);   
    startActivity(it);      
//用這個要在 AndroidManifest.xml 中加上   
    //<uses-permission id="android.permission.CALL_PHONE" />

  23.最基本的share 信息的intent可以传一段text信息到各个手机上已安装程序如SMSEmailsina微波米聊facebooktwitter等等         
         Intent it = new Intent(Intent.ACTION_SEND);                  it.putExtra(Intent.EXTRA_TEXT, "The email subject text"); 

  it.setType("text/plain");                  startActivity(Intent.createChooser(it, "Choose Email Client")); 

24.调用skype 的intent   方法1老版新版不可用可能是因为skype的activity结构变动 
//        Intent sky = new Intent("android.intent.action.CALL_PRIVILEGED");
//        sky.setClassName("com.skype.raider",
//                "com.skype.raider.contactsync.ContactSkypeOutCallStartActivity");
//        sky.setData(Uri.parse("tel:" + phone)); 
//        startActivity(sky);   方法2打开到skype的main page
  //        PackageManager packageManager = getActivity().getPackageManager();
  //        Intent skype = packageManager.getLaunchIntentForPackage("com.skype.raider");
//        skype.setData(Uri.parse("tel:65465446")); 
//        startActivity(skype);

  方法3传入号码直接进入skype拨号画面并打电话      
    Intent intent = new Intent("android.intent.action.CALL_PRIVILEGED");            intent.setClassName("com.skype.raider",      
   "com.skype.raider.Main");      
   intent.setData(Uri.parse("tel:" + phone));      
     startActivity(intent); 

 
  ★intent action大全  
android.intent.action.ALL_APPS  android.intent.action.ANSWER  android.intent.action.ATTACH_DATA  android.intent.action.BUG_REPORT  android.intent.action.CALL  android.intent.action.CALL_BUTTON  android.intent.action.CHOOSER  android.intent.action.CREATE_LIVE_FOLDER  android.intent.action.CREATE_SHORTCUT  android.intent.action.DELETE  android.intent.action.DIAL  android.intent.action.EDIT  android.intent.action.GET_CONTENT


25. ACTION_AIRPLANE_MODE_CHANGED 
Broadcast Action:用户打开或关闭飞行模式。一个或多个广播会打开或关闭。这个intent会携带下面的附加值: 
state:一个boolean值,指明飞行模式是否打开。如果是true,cell radio以及其他一些例如蓝牙,wifi的广播会关闭。 
注:这是一个只有系统可以发送的受保护的intent。 
常量值:"android.intent.action.AIRPLANE_MODE" 
  
26.ACTION_ALL_APPS 
Activity Action:列出所有可用的应用。 
常量值:"android.intent.action.ALL_APPS"  
  
27 .ACTION_ANSWER 
Activity Action:处理呼入的电话。 
常量值:"android.intent.action.ANSWER"  
  
28.ACTION_APP_ERROR 
Activity Action:当用户点击crash/ANR对话框的"Report"按钮时发出的intent。 
常量值:"android.intent.action.APP_ERROR" 
   
29.ACTION_ATTACH_DATA 
用于指明一些资源应该被附加到其他的地方。例如,一个图片资源可以被附加到一个联系人。它由接受者决定资源应该被附加到什么地方,这个intent不指明最终的目地。 
输入:getData()方法可以获取附加资源的URI。 
常量值:"android.intent.action.ATTACH_DATA" 
  
30.ACTION_BATTERY_CHANGED 
Broadcast Action:这是一个包含电池的充电状态,级别,和其他信息的复杂的广播。 
注:这是一个只有系统可以发送的受保护的intent。 
常量值:"android.intent.action.BATTERY_CHANGED"  
 
31.ACTION_BATTERY_LOW 
Broadcast Action:指示设备电量不足。这个广播会触发"电量不足警告"系统对话框。 
注:这是一个只有系统可以发送的受保护的intent。 
常量值:"android.intent.action.BATTERY_LOW" 
  
32.ACTION_BATTERY_OKAY 
Broadcast Action:指示电池从电量不足状态恢复。一旦电池从电量不足状态恢复这个广播会被触发。 
注:这是一个只有系统可以发送的受保护的intent。 
常量值:"android.intent.action.BATTERY_OKAY"  
 
33.ACTION_BOOT_COMPLETED 
Broadcast Action:系统启动完成后触发该intent。它可以用来执行应用指定的初始化工作,例如初始化闹钟。你必须指明RECEIVE_BOOT_COMPLETED权限来接收这个intent。 
注:这是一个只有系统可以发送的受保护的intent。 
常量值:"android.intent.action.BOOT_COMPLETED"  
 
34.ACTION_BUG_REPORT 
Activity Action:用来显示报告bug的activity。 
常量值:"android.intent.action.BUG_REPORT" 
  
35.ACTION_CALL 
Activity Action:根据指明的信息向某人拨打电话。 
输入:如果为空,启动一个空的拨号界面;如果不为空,通过getData()方法获取一个手机号码或者电话号码的URI进行拨号:URI是一个显示的手机号码。 
注:应用在初始化一个拨号事件时会受到一些限制;大部分的应用可以使用ACTION_CALL。 
注:这个intent不能用于进行紧急呼叫拨号。然而,应用程序可以通过ACTION_DIAL进行紧急呼叫拨号。 
常量值:"android.intent.action.CALL"  
 
36.ACTION_CALL_BUTTON 
Activity Action:用户点击拨号按钮进入拨号界面,或者其他适当的可以代替拨号界面的UI界面。 
常量值:"android.intent.action.CALL_BUTTON"  
 
37.ACTION_CAMERA_BUTTON 
Broadcast Action:点击拍照键。包含一个单独的额外字段:EXTRA_KEY_EVENT,包含触发这个广播的按键事件。 
常量值:"android.intent.action.CAMERA_BUTTON" 

猜你喜欢

转载自fsh430623.iteye.com/blog/1848687