Android開(kāi)發(fā)中Intent.Action各種常見(jiàn)的作用匯總
本文介紹Android中Intent的各種常見(jiàn)作用。
1 Intent.ACTION_MAIN
String: android.intent.action.MAIN
標(biāo)識(shí)Activity為一個(gè)程序的開(kāi)始。比較常用。
Input:nothing
Output:nothing
<activity android:name=".Main" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
2 Intent.Action_CALL
Stirng: android.intent.action.CALL
呼叫指定的電話號(hào)碼。
Input:電話號(hào)碼。數(shù)據(jù)格式為:tel:+phone number
Output:Nothing
Intent intent=new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:1320010001"); startActivity(intent);
使用Intent.ACTION_CALL時(shí),必須在AndroidManifest.xml中添加<uses-permission android:name="android.permission.CALL_PHONE" />已獲取撥打電話的權(quán)限。Intent.ACTION_CALL與Intent.ACTION_DIALOG不同,Intent.ACTION_DIALOG只是調(diào)用撥號(hào)鍵盤(pán),將電話號(hào)碼復(fù)制上去,而Intent.ACTION_CALL則是直接撥打電話
3 Intent.Action.DIAL
String: action.intent.action.DIAL
調(diào)用撥號(hào)面板
Intent intent=new Intent(); intent.setAction(Intent.ACTION_DIAL); //android.intent.action.DIAL intent.setData(Uri.parse("tel:1320010001"); startActivity(intent);
Input:電話號(hào)碼。數(shù)據(jù)格式為:tel:+phone number
Output:Nothing
說(shuō)明:打開(kāi)Android的撥號(hào)UI。如果沒(méi)有設(shè)置數(shù)據(jù),則打開(kāi)一個(gè)空的UI,如果設(shè)置數(shù)據(jù),action.DIAL則通過(guò)調(diào)用getData()獲取電話號(hào)碼。
但設(shè)置電話號(hào)碼的數(shù)據(jù)格式為 tel:+phone number.
4 Intent.Action.ALL_APPS
String: andriod.intent.action.ALL_APPS
列出所有的應(yīng)用。
Input:Nothing.
Output:Nothing.
5 Intent.ACTION_ANSWER
Stirng:android.intent.action.ANSWER
處理呼入的電話。
Input:Nothing.
Output:Nothing.
6 Intent.ACTION_ATTACH_DATA
String: android.action.ATTCH_DATA
別用于指定一些數(shù)據(jù)應(yīng)該附屬于一些其他的地方,例如,圖片數(shù)據(jù)應(yīng)該附屬于聯(lián)系人
Input: Data
Output:nothing
7 Intent.ACTION_BUG_REPORT
String: android.intent.action.BUG_REPORT
顯示Dug報(bào)告。
Input:nothing
output:nothing
8 Intent.Action_CALL_BUTTON
String: android.action.intent.CALL_BUTTON.
相當(dāng)于用戶按下“撥號(hào)”鍵。經(jīng)測(cè)試顯示的是“通話記錄”
Input:nothing
Output:nothing
Intent intent = new Intent(Intent.ACTION_CALL_BUTTON); startActivity(intent);
9 Intent.ACTION_CHOOSER
String: android.intent.action.CHOOSER
顯示一個(gè)activity選擇器,允許用戶在進(jìn)程之前選擇他們想要的,與之對(duì)應(yīng)的是Intent.ACTION_GET_CONTENT.
10. Intent.ACTION_GET_CONTENT
String: android.intent.action.GET_CONTENT
允許用戶選擇特殊種類的數(shù)據(jù),并返回(特殊種類的數(shù)據(jù):照一張相片或錄一段音)
Input: Type
Output:URI
int requestCode = 1001; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // "android.intent.action.GET_CONTENT" intent.setType("image/*"); // 查看類型,如果是其他類型,比如視頻則替換成 video/*,或 */* Intent wrapperIntent = Intent.createChooser(intent, null); startActivityForResult(wrapperIntent, requestCode);
11 Intent.ACTION_VIEW
String android.intent.action.VIEW
用于顯示用戶的數(shù)據(jù)。
比較通用,會(huì)根據(jù)用戶的數(shù)據(jù)類型打開(kāi)相應(yīng)的Activity。
比如 tel:13400010001打開(kāi)撥號(hào)程序,http://www.g.cn則會(huì)打開(kāi)瀏覽器等。
Uri uri = Uri.parse("http://www.google.com"); //瀏覽器 Uri uri =Uri.parse("tel:1232333"); //撥號(hào)程序 Uri uri=Uri.parse("geo:39.899533,116.036476"); //打開(kāi)地圖定位 Intent it = new Intent(Intent.ACTION_VIEW,uri); startActivity(it);
//播放視頻 Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse("file:///sdcard/media.mp4"); intent.setDataAndType(uri, "video/*"); startActivity(intent);
//調(diào)用發(fā)送短信的程序 Intent it = new Intent(Intent.ACTION_VIEW); it.putExtra("sms_body", "信息內(nèi)容..."); it.setType("vnd.android-dir/mms-sms"); startActivity(it);
12 Intent.ACTION_SENDTO
String: android.intent.action.SENDTO
說(shuō)明:發(fā)送短信息
//發(fā)送短信息 Uri uri = Uri.parse("smsto:13200100001"); Intent it = new Intent(Intent.ACTION_SENDTO, uri); it.putExtra("sms_body", "信息內(nèi)容..."); startActivity(it);
//發(fā)送彩信,設(shè)備會(huì)提示選擇合適的程序發(fā)送 Uri uri = Uri.parse("content://media/external/images/media/23"); //設(shè)備中的資源(圖像或其他資源) Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra("sms_body", "內(nèi)容"); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.setType("image/png"); startActivity(it);
//Email Intent intent=new Intent(Intent.ACTION_SEND); String[] tos={"android1@163.com"}; String[] ccs={"you@yahoo.com"}; intent.putExtra(Intent.EXTRA_EMAIL, tos); intent.putExtra(Intent.EXTRA_CC, ccs); intent.putExtra(Intent.EXTRA_TEXT, "The email body text"); intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text"); intent.setType("message/rfc822"); startActivity(Intent.createChooser(intent, "Choose Email Client"));
13 Intent.ACTION_GET_CONTENT
//選擇圖片 requestCode 返回的標(biāo)識(shí) Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //"android.intent.action.GET_CONTENT" intent.setType(contentType); //查看類型 String IMAGE_UNSPECIFIED = "image/*"; Intent wrapperIntent = Intent.createChooser(intent, null); ((Activity) context).startActivityForResult(wrapperIntent, requestCode);
//添加音頻 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*"; Intent wrapperIntent = Intent.createChooser(intent, null); ((Activity) context).startActivityForResult(wrapperIntent, requestCode);
//拍攝視頻 int durationLimit = getVideoCaptureDurationLimit(); //SystemProperties.getInt("ro.media.enc.lprof.duration", 60); Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit); intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationLimit); startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);
//視頻 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*"; Intent wrapperIntent = Intent.createChooser(intent, null); ((Activity) context).startActivityForResult(wrapperIntent, requestCode);
//錄音 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = "audio/amr"; intent.setClassName("com.android.soundrecorder", "com.android.soundrecorder.SoundRecorder"); ((Activity) context).startActivityForResult(intent, requestCode);
//拍照 REQUEST_CODE_TAKE_PICTURE 為返回的標(biāo)識(shí) Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //"android.media.action.IMAGE_CAPTURE"; intent.putExtra(MediaStore.EXTRA_OUTPUT, Mms.ScrapSpace.CONTENT_URI); // output,Uri.parse("content://mms/scrapSpace"); startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);
完畢。^_^
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
- Android顯式Intent與隱式Intent的使用詳解
- Android Intent傳遞大量數(shù)據(jù)出現(xiàn)問(wèn)題解決
- Android開(kāi)發(fā)Intent跳轉(zhuǎn)傳遞list集合實(shí)現(xiàn)示例
- Android13?加強(qiáng)Intent?filters?的安全性
- android使用intent傳遞參數(shù)實(shí)現(xiàn)乘法計(jì)算
- Android使用Intent的Action和Data屬性實(shí)現(xiàn)點(diǎn)擊按鈕跳轉(zhuǎn)到撥打電話和發(fā)送短信界面
- Android Intent傳遞數(shù)據(jù)大小限制詳解
- Android使用Intent隱式實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)
- Android Intent實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的兩種方法
- Android Intent基礎(chǔ)用法及作用詳解
相關(guān)文章
kotlin中object關(guān)鍵字的三種使用場(chǎng)景
這篇文章主要給大家介紹了關(guān)于kotlin中object關(guān)鍵字的三種使用場(chǎng)景,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用kotlin具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06安卓(android)怎么實(shí)現(xiàn)下拉刷新
這里我們將采取的方案是使用組合View的方式,先自定義一個(gè)布局繼承自LinearLayout,然后在這個(gè)布局中加入下拉頭和ListView這兩個(gè)子元素,并讓這兩個(gè)子元素縱向排列。對(duì)安卓(android)怎么實(shí)現(xiàn)下拉刷新的相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-04-04Android開(kāi)發(fā)之Android.mk模板的實(shí)例詳解
這篇文章主要介紹了Android開(kāi)發(fā)之Android.mk模板的實(shí)例詳解的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下2017-10-10Android動(dòng)態(tài)加載布局實(shí)現(xiàn)技巧介紹
通過(guò)使用LayoutInflater 每次點(diǎn)擊按鈕時(shí)候去讀取布局文件,然后找到布局文件里面的各個(gè)VIEW 操作完VIEW 后加載進(jìn)我們setContentView 方面里面的要放的布局文件里面,每次動(dòng)態(tài)加載文件必需調(diào)用 removeAllViews方法,清除之前的加載進(jìn)來(lái)的View2022-12-12詳解Android權(quán)限管理之RxPermission解決Android 6.0 適配問(wèn)題
本篇文章主要介紹了Android權(quán)限管理之RxPermission解決Android 6.0 適配問(wèn)題,具有一定的參考價(jià)值,有需要的可以了解一下。2016-11-11Android自定義FloatingActionButton滑動(dòng)行為只隱藏不出現(xiàn)的問(wèn)題小結(jié)
這篇文章主要介紹了Android自定義FloatingActionButton滑動(dòng)行為只隱藏不出現(xiàn)的問(wèn)題小結(jié),需要的朋友可以參考下2017-01-01Android開(kāi)發(fā)之自定義刮刮卡實(shí)現(xiàn)代碼
本篇文章主要介紹了Android開(kāi)發(fā)之自定義刮刮卡實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07Android App將數(shù)據(jù)寫(xiě)入內(nèi)部存儲(chǔ)和外部存儲(chǔ)的示例
這篇文章主要介紹了Android App將數(shù)據(jù)寫(xiě)入內(nèi)部存儲(chǔ)和外部存儲(chǔ)的示例,使用外部存儲(chǔ)即訪問(wèn)并寫(xiě)入SD卡,需要的朋友可以參考下2016-03-03