Android常用的intent action匯總
本文總結講述了Android常用的intent action功能。分享給大家供大家參考,具體如下:
Android基本的設計理念是鼓勵減少組件間的耦合,因此Android提供了Intent (意圖) ,Intent提供了一種通用的消息系統(tǒng),它允許在你的應用程序與其它的應用程序間傳遞Intent來執(zhí)行動作和產(chǎn)生事件。Intent作為聯(lián)系各Activity之間的紐帶,其作用并不僅僅只限于簡單的數(shù)據(jù)傳遞。通過其自帶的屬性,其實可以方便的完成很多較為復雜的操作。例如直接調用撥號功能、處理接收短信,諸如此類,都可以通過設置Intent屬性來完成。
Intent主要有以下四個重要屬性,它們分別為:
Action:Action屬性的值為一個字符串,它代表了系統(tǒng)中已經(jīng)定義了一系列常用的動作。通過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格式定義的操作數(shù)據(jù)。例如:tel:// 。通過setData()方法設置。
Category:Category屬性用于指定當前動作(Action)被執(zhí)行的環(huán)境。通過addCategory()方法或在清單文件AndroidManifest.xml中設置。默認為:CATEGORY_DEFAULT。
Extras:Extras屬性主要用于傳遞目標組件所需要的額外的數(shù)據(jù)。通過putExtras()方法設置。
在本文中,主要介紹常見action的使用,Action描述Intent所觸發(fā)動作名字的字符串,對于BroadcastIntent來說,Action指被廣播出去的動作。理論上Action可 以為任何字符串,而與Android系統(tǒng)應用有關的Action字符串以靜態(tài)字符串常量的形式定義在了Intent類中。Action中包含很多種,例如呼入,呼出電話,老師上課講的接受短信等等,下面謹對常見的與系統(tǒng)有關的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;
插上外部電源時發(fā)出的廣播
4 Intent.ACTION_POWER_DISCONNECTED;
已斷開外部電源連接時發(fā)出的廣播
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
允許用戶選擇特殊種類的數(shù)據(jù),并返回(特殊種類的數(shù)據(jù):照一張相片或錄一段音)
12. Intent.ACTION_BATTERY_LOW;
String: android.intent.action.BATTERY_LOW
表示電池電量低
13. Intent.ACTION_SEND
String: android.intent.action.Send
發(fā)送郵件的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系統(tǒng)都會廣播此Action消息
以上是對常見的action進行總結,action其實有很多,如果要使用上文沒有列舉到的,google即可。
更多關于Android相關內容感興趣的讀者可查看本站專題:《Android編程之a(chǎn)ctivity操作技巧總結》、《Android資源操作技巧匯總》、《Android文件操作技巧匯總》、《Android操作SQLite數(shù)據(jù)庫技巧總結》、《Android操作json格式數(shù)據(jù)技巧總結》、《Android數(shù)據(jù)庫操作技巧總結》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
相關文章
解決android設備斷電重啟后WIFI不能自動重連的BUG(收藏)
這篇文章主要介紹了解決android設備斷電重啟后WIFI不能自動重連的BUG,本文給出了問題描述及分析過程,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-11-11利用Jetpack?Compose復刻游戲Flappy?Bird
Flappy?Bird是13年紅極一時的小游戲,其簡單有趣的玩法和變態(tài)的難度形成了強烈反差,引發(fā)全球玩家競相把玩!本文將通過Jetpack?Compose復刻這一游戲,感興趣的小伙伴可以了解一下2022-02-02Android實現(xiàn)信號強度監(jiān)聽的方法
這篇文章主要介紹了Android實現(xiàn)信號強度監(jiān)聽的方法,是Android手機中很常見的一個實用功能,需要的朋友可以參考下2014-08-08詳解xamarin Android 實現(xiàn)ListView萬能適配器
這篇文章主要介紹了詳解xamarin Android 實現(xiàn)ListView萬能適配器的相關資料,這里主要實現(xiàn)listview 適配器的實例,需要的朋友可以參考下2017-08-08