intent用法很靈活,以下列出了intent的一些常用例項,主要包括activity的跳轉及啟動:
intent intent = new intent(activity.main.this, activity2.class);startactivity(intent);
intent intent = new intent(activity.main.this, activity2.class);bundle bundle=new bundle();
bundle.putstring("name", "this is from mainactivity!");
intent.putextras(bundle);
startactivity(intent); startactivityforresult(intent,request_code);
對於資料的獲取可以採用:
bundle bundle=getintent().getextras();string name=bundle.getstring("name");
intent intent=getintent(); bundle bundle=new bundle(); bundle.putstring("name", "this is from activity2!"); intent.putextras(bundle); setresult(result_ok, intent);
注:setresult(int resultcode, intent data);中的引數resultcode的作用是:在上乙個activity的onactivityresult函式中作為第二次判斷用(第一次判斷在startactivityforresult(intent intent, int requestcode);中指定)
@overrideprotected void onactivityresult(int requestcode, int resultcode, intent data) }}
uri uri = uri.parse("geo:38.899533,-77.036476"); intent intent = new intent(intent.action_view, uri); startactivity(intent); //其他 geo uri 範例 //geo:latitude,longitude //geo:latitude,longitude?z=zoom //geo:0,0?q=my+street+address //geo:0,0?q=business+near+city
uri uri = uri.parse(""); intent intent = new intent(intent.action_view, uri); startactivity(intent); //where startlat, startlng, endlat, endlng are a long with 6 decimals like: 50.123456
//叫出撥號程式 uri uri = uri.parse("tel:0800000123"); intent intent = new intent(intent.action_dial, uri); startactivity(intent); //直接打**出去 uri uri = uri.parse("tel:0800000123"); intent intent = new intent(intent.action_call, uri); startactivity(intent); //用這個,要在 androidmanifest.xml 中,加上 //
//呼叫簡訊程式 intent intent = new intent(intent.action_view, uri); intent.putextra("sms_body", "the sms text"); intent.settype("vnd.android-dir/mms-sms"); startactivity(intent); //傳送訊息 uri uri = uri.parse("smsto://0800000123"); intent intent = new intent(intent.action_sendto, uri); intent.putextra("sms_body", "the sms text"); startactivity(intent); //傳送 mms 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(it);
uri uri = uri.parse("mailto:***@abc.com"); intent intent = new intent(intent.action_sendto, uri); startactivity(intent); intent intent = new intent(intent.action_send); intent.putextra(intent.extra_email, "[email protected]"); 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_send); intent.putextra(intent.extra_subject, "the email subject text"); intent.putextra(intent.extra_stream, "file:///sdcard/mysong.***"); sendintent.settype("audio/***"); startactivity(intent.createchooser(intent, "choose email client"));
uri uri = uri.fromparts("package", strpackagename, null); intent intent = new intent(intent.action_delete, uri); startactivity(intent);
Intent用法例項
intent用法很靈活,以下列出了intent的一些常用例項,主要包括activity的跳轉及啟動 對於資料的獲取可以採用 注 setresult int resultcode,intent data 中的引數resultcode的作用是 在上乙個activity的onactivityresult函...
Intent 用法集合
顯示網頁 顯示地圖 uri uri uri.parse geo 38.899533,77.036476 intent it new intent intent.action view,uri startactivity it 其他 geo uri 範例 geo latitude,longitude ...
Intent用法 持續
0.intent 基礎知識 1.intent用法 1.1 用法1 從庫中得到,以uri形式返回 最終可以轉變成流,以流得到bitmap private static final int image get 1 intent intent new intent intent.action pick,a...