在Android中运行USSD代码,并将应用程序置于第一位 [英] Run USSD Code in Android and Keep the App in the firstground
本文介绍了在Android中运行USSD代码,并将应用程序置于第一位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Android中创建一个应用,该应用需要在后台运行USSD代码.无需在后台发送我的应用程序,
I am creating a App in Android, which required run USSD Code in background. without send my application in background,
每当我使用Intent.ACTION_CALL运行USSD
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.
因此可以在不打开前端拨号程序界面的情况下运行USSD代码.
So it is possible to run USSD code without open Dialer Interface in front.
谢谢.
推荐答案
使用以下代码:
String ussdCode = "*123#";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(ussdToCallableUri(ussdCode));
try{
startActivity(intent);
} catch (SecurityException e){
e.printStackTrace();
}
以下是将您的usdd代码转换为可调用的usd的方法:
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);
}
这篇关于在Android中运行USSD代码,并将应用程序置于第一位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文