Android Intent的幾種用法詳細(xì)解析
Intent應(yīng)該算是Android中特有的東西。你可以在Intent中指定程序要執(zhí)行的動作(比如:view,edit,dial),以及程序執(zhí)行到該動作時所需要的資料。都指定好后,只要調(diào)用startActivity(),Android系統(tǒng)會自動尋找最符合你指定要求的應(yīng)用程序,并執(zhí)行該程序。
下面列出幾種Intent的用法
顯示網(wǎng)頁:
Uri uri = Uri.parse("http://www.google.com");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
顯示地圖:
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = new Intent(Intent.Action_VIEW,uri);
startActivity(it);
路徑規(guī)劃:
Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent it = new Intent(Intent.ACTION_VIEW,URI);
startActivity(it);
撥打電話:
調(diào)用撥號程序
Uri uri = Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
Uri uri = Uri.parse("tel.xxxxxx");
Intent it =new Intent(Intent.ACTION_CALL,uri);
要使用這個必須在配置文件中加入<uses-permission id="android.permission.CALL_PHONE" />
發(fā)送SMS/MMS
調(diào)用發(fā)送短信的程序
Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "The SMS text");
it.setType("vnd.android-dir/mms-sms");
startActivity(it);
發(fā)送短信
Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
發(fā)送彩信
Uri uri = Uri.parse("content://media/external/images/media/23");
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra("sms_body", "some text");
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType("image/png");
startActivity(it);
發(fā)送Email
Uri uri = Uri.parse("mailto:xxx@abc.com");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");
it.putExtra(Intent.EXTRA_TEXT, "The email body text");
it.setType("text/plain");
startActivity(Intent.createChooser(it, "Choose Email Client"));
Intent it=new Intent(Intent.ACTION_SEND);
String[] tos={"me@abc.com"};
String[] ccs={"you@abc.com"};
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, "The email body text");
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.setType("message/rfc822");
startActivity(Intent.createChooser(it, "Choose Email Client"));
添加附件
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
sendIntent.setType("audio/mp3");
startActivity(Intent.createChooser(it, "Choose Email Client"));
播放多媒體
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
Uninstall 程序
Uri uri = Uri.fromParts("package", strPackageName, null);
Intent it = new Intent(Intent.ACTION_DELETE, uri);
startActivity(it);
- Android控件系列之TextView使用介紹
- android textview 顯示html方法解析
- Android的TextView與Html相結(jié)合的具體方法
- android Textview文字監(jiān)控(Textview使用方法)
- Android設(shè)置TextView顯示指定個數(shù)字符,超過部分顯示...(省略號)的方法
- Android中實現(xiàn)為TextView添加多個可點擊的文本
- android中Intent傳值與Bundle傳值的區(qū)別詳解
- android中intent傳遞list或者對象的方法
- 詳解Android中Intent的使用方法
- Android Intent啟動別的應(yīng)用實現(xiàn)方法
- Android開發(fā)之TextView使用intent傳遞信息,實現(xiàn)注冊界面功能示例
相關(guān)文章
Android高效加載大圖、多圖解決方案 有效避免程序OOM
這篇文章主要為大家詳細(xì)介紹了Android高效加載大圖、多圖解決方案,有效避免程序OOM,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10
詳解Android studio 3+版本apk安裝失敗問題
這篇文章主要介紹了詳解Android studio 3+版本apk安裝失敗問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04
如何設(shè)置Android studio 3.0顯示光標(biāo)返回上一次瀏覽位置的箭頭圖標(biāo)
這篇文章主要介紹了如何設(shè)置Android studio 3.0顯示光標(biāo)返回上一次瀏覽位置的箭頭圖標(biāo) 很多朋友反映剛升級了Android studio 3.0,發(fā)現(xiàn)光標(biāo)返回上一次瀏覽位置的箭頭圖標(biāo)沒有了,下文給大家介紹的非常詳細(xì),需要的朋友可以參考下2017-11-11
Android實現(xiàn)pdf在線預(yù)覽或本地預(yù)覽的方法
下面小編就為大家分享一篇Android實現(xiàn)pdf在線預(yù)覽或本地預(yù)覽的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01
Android實現(xiàn)錄音監(jiān)聽動畫的示例代碼
在很多app種內(nèi)置了語音助手,也存在各種動畫,這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)錄音監(jiān)聽動畫的示例代碼,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-12-12

