Last active
August 27, 2020 13:29
-
-
Save aslamanver/2267e3b06d940e796761040a4cc65687 to your computer and use it in GitHub Desktop.
Android USSD Send - Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void sendLongSMS() { | |
String ussdCode = "#456#"; | |
Intent intent = new Intent(Intent.ACTION_CALL); | |
intent.setData(ussdToCallableUri(ussdCode)); | |
try { | |
startActivity(intent); | |
} catch (SecurityException e) { | |
e.printStackTrace(); | |
} | |
} | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment