android開発 Intentを使って電話を掛ける方法

androidプログラムから簡単に電話をかけることができます。

 

Intent intent = new Intent(
Intent.ACTION_CALL,
Uri.parse("tel:1234567890"));

startActivity(intent);

 

またマニフェストに以下のパーミッションを追加する必要があります。

<uses-permission android:name="android.permission.CALL_PHONE"/>

 

パーミションを追加しない場合はエラーが表示されます。

FATAL EXCEPTION: main

java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxxx cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{42e111c8 14077:com.example.IntentTel/u0a96} (pid=14077, uid=10096) requires android.permission.CALL_PHONE

 

そのままですね。

IntentさんがCALL_PHONEのパーミションを必要としていますよ。

 

電話をかけるソースコードは - 逆引きAndroid入門