4

I am building a call forwarding application and have used the **21*xxxxxx# ussd code to activate call fowarding using ACTION_CALL Intent. But I have not found a solution to check whether Call forwarding is active or not.

Is there any solution to check from the android system if call forwarding is active or not?

Varun Agarwal
  • 177
  • 1
  • 5
  • 12

4 Answers4

6
 TelephonyManager manager = (TelephonyManager)    
 this.getSystemService(TELEPHONY_SERVICE);     
 manager.listen(new MyPhoneStateListener(), 
 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR ); 

 class MyPhoneStateListener extends PhoneStateListener{  

  @Override
    public void onCallForwardingIndicatorChanged(boolean cfi) {
      Log.i(TAG,"onCallForwardingIndicatorChanged  CFI ="+cfi);

         preferences.edit().putBoolean("CALL_FORWARD_ACTIVE", cfi).commit();
        super.onCallForwardingIndicatorChanged(cfi);
    }

}

if cfi returns true that means set call forward success

Matt
  • 13,948
  • 6
  • 44
  • 68
laiwenjie
  • 81
  • 1
  • 4
  • This only works if forwarding is active for all calls (unconditionally). Is there a way to listen if there is a forwarding active when busy? – Jordy Sep 05 '16 at 11:04
2

PRECAUTION: The following answer is suggestion. I haven't tried it personally So you better try it to check the result.

From your gsm number you can check your call forwarding options by dialing *#21#. So you can try dialing this number from application and read the ussd response.

part 1: to dial the number

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

part 2: to read the ussd response

There is no API to do this. But here in this SO answer it suggested some methods that you can try.

Best of luck

Community
  • 1
  • 1
stinepike
  • 54,068
  • 14
  • 92
  • 112
2

you can make Brodcast class register it and you can track out going call like

public class CallBroadcastReceiver extends BroadcastReceiver
{
    public static String numberToCall;
    public void onReceive(Context context, Intent intent) {
        Log.d("CallRecorder", "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);
        }

    }
}
Ankitkumar Makwana
  • 3,475
  • 3
  • 19
  • 45
0

yes you can use *#21# to check for CF in the same way as you used **21*xxxxxx# to activate CF. BTW, these are MMI code, not USSD code.

rfabbc
  • 1
  • 1