I am creating a App in Android, which required run USSD Code in background. without send my application in background,
Whenever I am using Intent.ACTION_CALL to run USSD
String ussdCode = "*" + "123" + Uri.encode("#");
startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + ussdCode)));
it send my application in background, and open dialer Interface on my application.
So it is possible to run USSD code without open Dialer Interface in front.
Thanks.
This app can be found on your home screen, on the "All Apps" screen, or, on simpler cell phones, on the lock screen. Dial the USSD code. Some start with *, others #, and others *#. Dial #.
USSD applications run on the network, not on a user's device. As such, they don't have to be installed on the user's phone, which is an advantage for users with feature phones that have limited storage space. USSD apps are instantly available to every subscriber the moment they're deployed to a network.
Use following code:
String ussdCode = "*123#";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(ussdToCallableUri(ussdCode));
try{
startActivity(intent);
} catch (SecurityException e){
e.printStackTrace();
}
Here is the method to convert your ussd code to callable ussd:
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With