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