Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Retrieve Call forwarding State in Android througn code?

Is it possible to retrieve the call forwarding state on Android?

enter image description here

Using this code only shows a popup with the current state but I was wondering if it's possible to get the actual number that is set if any

Intent intentCallForward = new Intent(Intent.ACTION_CALL);                               
Uri uri = Uri.fromParts("tel", "*#21#", "#"); 
intentCallForward.setData(uri);                                
startActivity(intentCallForward);
like image 777
Paulo Taylor Avatar asked Nov 29 '12 15:11

Paulo Taylor


1 Answers

It's simple. All you need is a BroadCast to be tracking your phone state. Try something like this:

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);
        }
    }
}
like image 164
Chrome Landos Avatar answered Nov 14 '22 04:11

Chrome Landos