発信コールに応答したときのステータスを取得する方法が必要です。ただし、OFFHOOK状態では、発信コール(ACTION_CALL)を呼び出すためにも使用しています。発信アクティビティをオーバーライドせずにawnsered状態を追加するにはどうすればよいですか?Androidで発信コールを受信する方法
public class OutgoingBroadcastReceiver extends BroadcastReceiver {
private Intent mIntent;
private String phonenumber = null;
public static boolean wasRinging;
@Override
public void onReceive(Context context, Intent intent) {
mIntent = intent;
MyPhoneStateListener phoneListener = new MyPhoneStateListener(context);
TelephonyManager telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
}
public class MyPhoneStateListener extends PhoneStateListener {
private final Context context;
public MyPhoneStateListener(Context context) {
this.context = context;
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
wasRinging = true;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.e("%%%%%%%%%%%%%%%%%%%%%%%%%%%t", "OFFHOOK");
if (UIUDialer.isOutgoingCall() == true) {
//Do my work when outgoing call is detected
}
else if (!wasRinging)
{
Log.e("%%%%%%%%%%%%%%%%%%%%%%%%%%%t", "WASRINGING");
//Do my work when outgoing call is awnsered
}
context.sendBroadcast(new Intent("finish_incoming"));
wasRinging = true;
break;
case TelephonyManager.CALL_STATE_RINGING:
wasRinging = true;
break;
}
}
}
}
ステート 'CALL_STATE_RINGING'は' OUTGOING_CALL'では**呼び出されません**ので、変数wasRingingは常にfalseに設定されます。 – Houcine