Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 電話撥號器實作:Intent 與權限設定

編輯:關於 Android 開發

電話撥號器實作重點

一個簡單的 Android 撥號功能,通常由產品、UI、架構、開發、測試與營運等角色共同完成。就開發端而言,核心包含介面布局、事件綁定、Intent 啟動撥號動作,以及權限宣告。

實作流程

  1. 在布局檔案中建立輸入框與按鈕,並為元件設定 id。
  2. 在 Activity 中使用 findViewById 取得 EditText 與 Button 物件。
  3. 為按鈕設定點擊監聽器。
  4. 在點擊事件中取得使用者輸入的電話號碼。
  5. 建立 Intent,設定動作為 ACTION_CALL。
  6. 使用 setData 設定 tel URI。
  7. 呼叫 startActivity 啟動撥號。
  8. 在 AndroidManifest.xml 加入 CALL_PHONE 權限。
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
startActivity(intent);

若僅想開啟撥號介面而不直接撥打,可改用 ACTION_DIAL,通常不需要直接撥號權限。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved