使用 Intent.ACTION_CALL 啟動撥號,但畫面僅顯示號碼需手動按呼叫鍵,無法直接撥出。
必須在 AndroidManifest.xml 中宣告 CALL_PHONE 權限:
<uses-permission android:name="android.permission.CALL_PHONE" />
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + numberToCall));
startActivity(callIntent);
ACTION_DIAL 僅開啟撥號介面,不需權限但需手動按鍵。ACTION_CALL 直接撥打,需 CALL_PHONE 權限(API 23+ 還需執行期權限請求)。CALL_PRIVILEGED,一般應用不可用。Android 6.0 (API 23) 以上需動態請求權限,否則會擲出 SecurityException。