Make USSD call in android

To check the balance, first I need to make a call * xxx # , and then I get a response with several options to choose from and after entering a specific number I get a balance.

What code can I use for my Android app?

Dialing * xxx * x # gives me an error.

Below is my code, which is great for * xxx # calls:

String encodedHash = Uri.encode("#"); String ussd = "*" + encodedHash + lCallNum + encodedHash; startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd))); 
+6
source share
7 answers

This works for me:

 private Uri ussdToCallableUri(String ussd) { String uriString = ""; if(!ussd.startsWith("tel:")) uriString += "tel:"; for(char c : ussd.toCharArray()) { if(c == '#') uriString += Uri.encode("#"); else uriString += c; } return Uri.parse(uriString); } 

Then in the working code:

 Intent callIntent = new Intent(Intent.ACTION_CALL, ussdToCallableUri(yourUSSDCodeHere)); startActivity(callIntent); 
+11
source

Do not forget to add permission, it will solve the skype: P problem

 <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> 
+4
source
 String ussd = "*XXX*X" + Uri.encode("#"); startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd))); 

It works great with me. just put the first bunch and then encode # to make it complete *XXX*X# . it will definitely help

+3
source

Important to remember:

If you are targeting Android Marshmallow (6.0) or higher, you need to request permission to Manifest.permission.CALL_PHONE at runtime

+3
source

Try it, I have not tested it, but should work.

 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode("*3282#"))); startActivity(intent); 
+2
source

Use this code. This works for me:

 Intent intent = new Intent(Intent.ACTION_CALL); intent.setData(Uri.parse(Uri.parse("tel:" + "*947")+Uri.encode("#"))); startActivity(intent); 
+1
source

Use this code, it works

 Intent callIntent = new Intent(Intent.ACTION_CALL); String ussdCode = "*" + 2 + Uri.encode("#"); callIntent.setData(Uri.parse("tel:" +ussdCode)); if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { return; } startActivity(callIntent); 

Add this line to the manifest file.

 <uses-permission android:name="android.permission.CALL_PHONE" /> 
0
source

Source: https://habr.com/ru/post/948132/


All Articles