幾種Intent的用法

2021-06-16 05:20:32 字數 3482 閱讀 1414

顯示網頁:

uri uri = uri.parse("");

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

路徑規劃:

uri uri = uri.parse("");

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

startactivity(it);

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

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

startactivity(it);  

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

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

要使用這個必須在配置檔案中加入

傳送sms/mms

呼叫傳送簡訊的程式

intent it = new intent(intent.action_view);

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

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

startactivity(it);  

傳送簡訊

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

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

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

startactivity(it);  

傳送彩信

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

傳送email

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

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

startactivity(it);

intent it = new intent(intent.action_send);

it.putextra(intent.extra_email, "[email protected]");

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=;    

string ccs=;    

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

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

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

intent it = new intent(intent.action_view);

uri uri = uri.parse("file:///sdcard/song.***");

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

startactivity(it);

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

install 程式

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

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

搜尋應用

//搜尋應用

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

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

startactivity(it);  

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

startactivity(it);  

//page, and notice the id from the address bar

Intent的幾種用法

returnit new intent intent.action delete,uninstalluri install apk uri installuri uri.fromparts package null returnit new intent intent.action package ...

Intent的幾種用法

intent 應該算是android中特有的東西。你可以在intent中指定程式 要執行的動作 比如 view,edit,dial 以及程式執行到該動作時所需要的資料。都指定好後,只要呼叫startactivity android系統會自動尋找最符合你指定要求的應用 程式,並執行該程式。下面列出幾種...

Intent的幾種用法

顯示網頁 顯示地圖 1.uri uri uri.parse geo 38.899533,77.036476 2.intent it new intent intent.action view,uri 3.startactivity it 4.其他geo uri 範例5.geo latitude,lo...