ユーザが電話をかけたときのインテントを受信してみる

ユーザが電話をかけたときのインテントを受信してみます。

public static final String ACTION_NEW_OUTGOING_CALL
Broadcast Action: An outgoing call is about to be placed.
Intent | Android Developers

AndroidManifest.xml

		<receiver android:name="ExBroadcastReceiver">
			<intent-filter>
				<action android:name="android.intent.action.NEW_OUTGOING_CALL"></action>
			</intent-filter>
		</receiver>

ExBroadcastReceiver.java

public class ExBroadcastReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		Toast.makeText(context, "onReceive", Toast.LENGTH_SHORT).show();
	}

}

上記だけでは、電話をかけたインテントは受信できませんでした。リファレンスをよく見たらパーミッションが必要と書いてありました。

You must hold the PROCESS_OUTGOING_CALLS permission to receive this Intent.

AndroidManifest.xml

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

これにより、ExBroadcastReceiverはユーザの電話発信インテントを受信できました。