Android實現撥號功能

來源:互聯網
上載者:User

標籤:

撥號介面:
 
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:orientation="vertical" >
  5. <!-- match_parent: 匹配父元素,父元素有多寬,我就有多寬;父元素有多高,我就有多高 -->
  6. <!-- wrap_content:包裹內容,我的內容有多高,我就有多高,我的內容有多寬,我就有多寬 -->
  7. <EditText
  8. android:id="@+id/et_input_num"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content"
  11. android:inputType="phone" >
  12. </EditText>
  13. <!-- android:text: 指定按鈕上的顯示文字 -->
  14. <!-- android:onClick: 定義點擊事件 -->
  15. <Button
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:onClick="call"
  19. android:text="打電話" />
  20. </LinearLayout>

// v: 代表你點擊的控制項public void call(View view) {           EditText editText = (EditText) findViewById(R.id.input_num);            // 擷取使用者輸入的手機號            String phone_number = editText.getText().toString();    //刪除字串首部和尾部的空格   
        phone_number = phone_number.trim();         /**             * context : 上下文,環境 <br/>             * text : 要顯示的內容 <br/>            * duration : 顯示的時常   //期間             *              */            Toast.makeText(this, phone_number, Toast.LENGTH_LONG);        if(phone_number != null && !phone_number.equals("")) {          //調用系統的撥號服務實現電話撥打功能             // 打電話            // Intent : 意圖.我想去做一件事            Intent t = new Intent();            // Action:動作.我具體想做什麼事            // Intent.ACTION_DIAL: 啟用撥號介面            // Intent.ACTION_CALL: 直接撥打到電話           t.setAction(Intent.ACTION_CALL);            // Data: 資料.具體的動作所需要的附加資料           //封裝一個撥打到電話的intent,並且將電話號碼封裝成一個Uri對象傳入         t.setData(Uri.parse("tel:" + phone_number));            // 通知系統你去幫我幹活吧            startActivity(t);}          } 最後在在AndroidManifest.xml裡面添加<uses-permission android:name="android.permission.CALL_PHONE"/> 

備忘:Toast.makeText()使用方法1.預設的顯示方式
2.自訂顯示位置3.帶圖片的4.完全自訂顯示方式




來自為知筆記(Wiz)

Android實現撥號功能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.