Call (and get the response for) a USSD Code, in the background?

后端 未结 6 1697
野性不改
野性不改 2020-12-05 18:30

I\'m wanting to write a widget displays the users\' prepay balance, remaining data etc.

I\'m thinking of automatically calling the USSD code which returns this data

6条回答
  •  有刺的猬
    2020-12-05 19:28

    You can use the following code to call the ussd codes on android phone to check the balance and etc......

       String s=calledittext.getText.toString();//calledittext is editText on the 
      //screen   from  which  can get the number
              if((s.startsWith("*"))&&(s.endsWith("#"))){
                //if true then it is a USSD call----
                callstring=s.substring(0, s.length()-1);
                callstring=callstring+Uri.encode("#");
    
        Log.d("CALL TYPE---------->", "USSD CALL"); 
            }else{
                callstring=s;   
        Log.d("CALL TYPE---------->", "Not a USSD CALL");   
        //Intent i=new Intent(android.content.Intent.ACTION_CALL,Uri.parse("tel:"+output.getText().toString()));
        //startActivity(i);
            }
        Intent i=new Intent(android.content.Intent.ACTION_CALL,Uri.parse("tel:"+callstring));
        startActivity(i);
    

提交回复
热议问题