如何通过代码在Android中检索呼叫转发状态?

时间:2012-11-29 15:59:31

标签: android android-intent phone-call

是否可以在Android上检索呼叫转移状态?

enter image description here

使用此代码仅显示具有当前状态的弹出窗口,但我想知道是否可以获得设置的实际数字(如果有)

Intent intentCallForward = new Intent(Intent.ACTION_CALL);                               
Uri uri = Uri.fromParts("tel", "*#21#", "#"); 
intentCallForward.setData(uri);                                
startActivity(intentCallForward);

1 个答案:

答案 0 :(得分:1)

很简单。您只需BroadCast跟踪手机状态即可。尝试这样的事情:

public class CallBroadcastReceiver extends BroadcastReceiver
{
    public static String numberToCall;
    public void onReceive(Context context, Intent intent) {
        Log.d("CallForwardingBroadCast", "CallBroadcastReceiver::onReceive got Intent: " + intent.toString());
        if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
            numberToCall = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            Log.d("CallRecorder", "CallBroadcastReceiver intent has EXTRA_PHONE_NUMBER: " + numberToCall);
        }
    }
}