java 如何在安卓上运行 USSD 命令?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7225100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run USSD commands on android?
提问by Michael Frans
has anyone know how to runs USSD command for checking phone's credit balance (the number is *123#) and get the result (the credit balance) for further processing?? thankss
有谁知道如何运行 USSD 命令来检查手机的信用余额(号码是 *123#)并获得结果(信用余额)以进行进一步处理?谢谢
回答by Bosah Chude
You can run USSD codes in Android devices but you would be unable to parse the result in your application. This feature might be added to the Android SDK in the future but for now, you would have to look for an alternative.
您可以在 Android 设备中运行 USSD 代码,但您将无法在您的应用程序中解析结果。此功能将来可能会添加到 Android SDK 中,但现在,您必须寻找替代方案。
USSD can be run using simple Call intents. See Example:
USSD 可以使用简单的 Call 意图运行。参见示例:
String ussdCode = "*" + "123" + Uri.encode("#");
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussdCode)));
as mentioned in the comments phone call permission is also required
如评论中所述,还需要电话许可
<uses-permission android:name="android.permission.CALL_PHONE" /
回答by user3469914
You can use "%23" instead of "#" :
您可以使用 "%23" 而不是 "#" :
String ussdCode = "*" + "123"+"%23";
startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + ussdCode)));
You should also add permission to your Manifest file:
您还应该为您的清单文件添加权限:
<uses-permission android:name="android.permission.CALL_PHONE" />