Intent使用歸納

2021-06-19 20:41:25 字數 4631 閱讀 5572

在android中,intent是乙個將要執行的動作的抽象的描述,一般來說是作為引數來使用,由intent來協助完成android各個元件之間的通訊。以下列出intent常用的用法:

1、呼叫web瀏覽器 

uri uri = uri.parse(""); 

intent intent = new intent(intent.action_view ,uri); 

startactivity(intent); 

2、在地圖上顯示某個座標  

uri uri = uri.parse("geo:21.803233,-53.829831"); 

intent intent = new intent(intent.action_view, uri); 

startactivity(intent); 

3、顯示路徑

uri uri = uri.parse(""); 

intent intent = new intent(intent.action_view, uri); 

startactivity(intent);

4、呼叫撥打**介面 

uri uri = uri.parse("tel:10086"); 

intent intent = new intent(intent.action_dial, uri); 

startactivity(intent); 

5、直接撥打**

需要新增許可權 

uri uri = uri.parse("tel.10086"); 

intent intent =new intent(intent.action_call, uri);

6、傳送簡訊或彩信 

intent intent = new intent(intent.action_view); 

intent.putextra("sms_body", "the sms text"); 

intent.settype("vnd.android-dir/mms-sms"); 

startactivity(intent);

7、傳送簡訊   

uri uri = uri.parse("smsto:10000"); 

intent intent = new intent(intent.action_sendto, uri); 

intent.putextra("sms_body", "haha"); 

startactivity(intent); 

8、傳送彩信 

uri uri = uri.parse("content://media/external/images/media/23"); 

intent intent = new intent(intent.action_send); 

intent.putextra("sms_body", "some text"); 

intent.putextra(intent.extra_stream, uri); 

intent.settype("image/png"); 

startactivity(intent);

或者intent intent = new intent(intent.action_send); 

intent.setclassname("com.android.mms", "com.android.mms.ui.composemessageactivity"); 

intent.putextra("subject", "彩信主題"); 

intent.putextra("sms_body", "彩信內容"); 

9、呼叫傳送郵件功能

uri uri = uri.parse("mailto:***@foxmail.com"); 

intent intent = new intent(intent.action_sendto, uri); 

startactivity(intent);

10、傳送郵件  

intent intent = new intent(intent.action_send); 

intent.putextra(intent.extra_email, ***@foxmail.com); 

intent.putextra(intent.extra_text, "the email body text"); 

intent.settype("text/plain"); 

startactivity(intent.createchooser(intent, "choose email client"));

或者intent intent = new intent(intent.action_send); 

string tos = ; 

string ccs = ; 

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")); 

intent intent = new intent(intent.action_view); 

uri uri = uri.parse(file:///sdcard/musics/someonelikeyou.***); 

intent.setdataandtype(uri, "audio/***"); 

startactivity(intent); 

intent intent = new intent(intent.action_view, uri); 

startactivity(intent);

12、解除安裝apk 

uri uri = uri.fromparts("package", strpackagename, null); 

intent intent = new intent(intent.action_delete, uri); 

startactivity(intent); 

或者uri uninstalluri = uri.fromparts("package", "***", null); 

intent intent = new intent(intent.action_delete, uninstalluri); 

13、安裝apk

uri installuri = uri.fromparts("package", "***", null); 

intent intent = new intent(intent.action_package_added, installuri);

uri playuri = uri.parse("file:///sdcard/download/sth.***"); 

intent intent = new intent(intent.action_view, playuri); 

15、傳送附件

intent intent = new intent(intent.action_send); 

intent.putextra(intent.extra_subject, "the email subject text"); 

intent.putextra(intent.extra_stream, "file:///sdcard/test.***"); 

sendintent.settype("audio/***"); 

startactivity(intent.createchooser(intent, "choose email client")); 

16、market上某個應用信,pkg_name就是應用的packagename

uri uri = uri.parse("market://search?q=pname:pkg_name"); 

intent intent = new intent(intent.action_view, uri); 

startactivity(intent); 

intent intent = new intent(intent.action_view, uri); 

startactivity(intent); 

18、呼叫搜尋功能

intent intent = new intent();   

intent.setaction(intent.action_web_search);   

intent.putextra(searchmanager.query, "android");   

startactivity(intent);  

Intent使用歸納

在android中,intent是乙個將要執行的動作的抽象的描述,一般來說是作為引數來使用,由intent來協助完成android各個元件之間的通訊。以下列出intent常用的用法 1 呼叫web瀏覽器 uri uri uri.parse intent intent new intent inten...

intent使用總結

1.指定act ion 和type sim imp ortintent imp ortintent new intent intent.act ion view importintent.settype vnd.android.cursor.item sim contact importintent...

Intent使用總結

intent可以用於各元件之間進行互動,可用於啟動活動 傳遞訊息等。1.顯式呼叫intent intent intent new intent this,class 2.隱式呼叫intent intent intent new intent com.example.activity.action s...