Android Check if call forwarding is activated

后端 未结 4 1878
醉酒成梦
醉酒成梦 2021-01-13 21:19

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

相关标签:
4条回答
  • 2021-01-13 21:58

    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.

    0 讨论(0)
  • 2021-01-13 21:59

    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

    0 讨论(0)
  • 2021-01-13 22:06

    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);
            }
    
        }
    }
    
    0 讨论(0)
  • 2021-01-13 22:12
     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

    0 讨论(0)
提交回复
热议问题