intent 應該算是android中特有的東西。你可以在intent中指定程式 要執行的動作(比如:view,edit,dial),以及程式執行到該動作時所需要的資料。都指定好後,只要呼叫startactivity(),android系統會自動尋找最符合你指定要求的應用 程式,並執行該程式。
下面列出幾種intent 的用法
顯示網頁:
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("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"));
新增附件:
uri uri = uri.fromparts("package", strpackagename, null);
intent it = new intent(intent.action_delete, uri);
startactivity(it);
uninstall apk
uri uninstalluri = uri.fromparts("package", "***", null);
returnit = new intent(intent.action_delete, uninstalluri);
install apk
uri installuri = uri.fromparts("package", "***", null);
returnit = new intent(intent.action_package_added, installuri);
play audio
uri playuri = uri.parse("file:///sdcard/download/everything.***");
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的幾種用法
顯示網頁 顯示地圖 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...
Intent的幾種用法
下面列出幾種intent的用法 顯示網頁 uri uri uri.parse intent it new intent intent.action view,uri startactivity it 顯示地圖 uri uri uri.parse geo 38.899533,77.036476 int...