android 常用的intent action整理

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消息
    以上是對常見的action進行總結,action其實有很多,如果要使用上文沒有列舉到的,google即可。
發佈了9 篇原創文章 · 獲贊 22 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章