[英]Run USSD Code in Android without using “ Intent.ACTION_CALL”
[英]Run USSD Code in Android and Keep the App in the firstground
我正在Android中创建一个应用程序,需要在后台运行USSD代码。 没有在后台发送我的申请,
每当我使用Intent.ACTION_CALL运行USSD时
String ussdCode = "*" + "123" + Uri.encode("#");
startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + ussdCode)));
它在后台发送我的应用程序,并在我的应用程序上打开拨号程序接口。
因此,可以在没有打开拨号器接口的情况下运行USSD代码。
谢谢。
使用以下代码:
String ussdCode = "*123#";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(ussdToCallableUri(ussdCode));
try{
startActivity(intent);
} catch (SecurityException e){
e.printStackTrace();
}
这是将你的ussd代码转换为可调用的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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.