そのコードを使用して、標準のダイヤルパッドからの呼び出しをキャッチしてみます:
<action android:name="android.intent.action.CALL" />
<data android:scheme="tel" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.CALL_PRIVILEGED" />
</intent-filter>
</activity>
ユーザーが標準の電話ダイヤルパッドからダイヤルすると、すべて問題なく、アプリが開きました。しかし、どのユーザーがダイヤルしたか、電話番号を取得する方法がわかりません。PhonePadActivity アクティビティ onCreate ブロック内のそのコード:
Intent intent = getIntent();
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(this, "Call was made to-->>" + number, 5000).show();
最後にnullを返します:(
ブロードキャストレシーバーを使用しようとしました:
マニフェストで:
<receiver android:exported="true" android:name="com.myapps.android.DialBroadcastReceiver" > <intent-filter > <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> </intent-filter> </receiver> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
これはクラス DialBroadcastReceiver です。
package com.myapps.android;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class DialBroadcastReceiver extends BroadcastReceiver {
private static final String THIS_FILE = "PhonePadActivity";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.e(THIS_FILE,"In onReceive()");
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.e(THIS_FILE,"Number is: "+number);
}
}
}
ただし、ユーザーがダイヤルを押すと、nodが発生したことをログに記録します