Android學習筆記(十七)——使用意圖調用內建應用程式程式

來源:互聯網
上載者:User

標籤: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。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.