を次のあなたは、BroadcastReceiverを実装し、このようなテレフォニーイベントを扱うことができます。
public class CallListener extends BroadcastReceiver {
private static final String OUTGOING_CALL_ACTION = Intent.ACTION_NEW_OUTGOING_CALL;
private static boolean isOutgoingCall;
private static String savedNumber;
@Override
public void onReceive(Context context, Intent intent) {
int event = -1;
String action = intent.getAction();
if (action.equals(OUTGOING_CALL_ACTION)) {
// get phone number from bundle
savedNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
isOutgoingCall = true;
}
else
{
//gets phone's state
String phoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if(phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
isOutgoingCall = false;
//gets the phone number of this incoming call
savedNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.d(TAG, String.format("Received phone call from [%s]", savedNumber));
}
else if(phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE))
{
// call ended
Log.i(TAG, TelephonyManager.EXTRA_STATE_IDLE);
savedNumber = null;
event = InCallManager.CALL_STATE.EVENT_IDLE;
}
else if(phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
{
// call answered
if(isOutgoingCall) {
event = InCallManager.CALL_STATE.EVENT_OUTCALL;
isOutgoingCall = false;
}
else {
event = InCallManager.CALL_STATE.EVENT_INCALL;
}
}
}
}
}
マニフェストで
だけ追加します。
<receiver android:name="receivers.CallListener">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
を使用し、私はわからないが、これをチェックしてください[link] [1]それはあなたを助けるかもしれません [1]:http://stackoverflow.com/a/15564021/2492925 –