標籤:android webbrowser intent 對象 內建應用程式程式
使用意圖調用內建應用程式程式
1、建立一個新的Android項目並命名為Intents,在main.xml檔案中添加兩個Button:
<Button android:id="@+id/btn_webbrowser" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="onClickWebBrowser" android:text="Web Browser" /> <Button android:id="@+id/btn_makecalls" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="onClickMakeCalls" android:text="Make Calls" />
2、在IntentsActivity.java檔案中添加如下代碼:
public void onClickWebBrowser(View v) {//瀏覽器Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://網址"));//網址處輸入百度網址,CSDN不讓直接寫網址...startActivity(intent);}public void onClickMakeCalls(View v) {//打電話Intent intent = new Intent(android.content.Intent.ACTION_DIAL,Uri.parse("tel:+651234567"));startActivity(intent);}
3、運行程式,效果如下:
點擊Web Browser:
點擊Make Calls:
總結:
在Android中,意圖通常是成對出項:動作(Action)和資料(data)。動作描述了要執行什麼,資料則指定了受影響的對象。
動作的一些樣本:Action_VIEW、ACTION_DIAL、ACTION_PICK;
資料的一些樣本:tel:+651234567、geo:37.827500,-122.481670、content://contacts。