简体   繁体   English

Android 工作室动作调用运行 USSD 代码

[英]Android studio Action call to run USSD codes

By using an app I want to run a USSD code, but the problem is it doesn't recognize the "#" symbol.通过使用我想运行 USSD 代码的应用程序,但问题是它无法识别“#”符号。 If I want to run "*100#" it recognize the input only as "*100".如果我想运行“*100#”,它只会将输入识别为“*100”。 How to add the "#".如何添加“#”。 and what is the reason to not recognize that?不承认这一点的原因是什么?

Here is my code...这是我的代码...

  checkBalance.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent i = new Intent(Intent.ACTION_CALL);


            i.setData(Uri.parse("tel:"+"*100#"));

            if (ActivityCompat.checkSelfPermission(mobitelPage.this,
                    Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            startActivity(i);



        }
    });

You need to use Uri.encode("YOUR USSD CODE") in Uri.Parse() .您需要在Uri.Parse()使用Uri.encode("YOUR USSD CODE") Uri.Parse()

Example:示例:

Uri.parse("tel:"+ Uri.encode("*100#"));

Try this code.Use Uri.encode("#") :试试这个代码。使用Uri.encode("#")

    String encodedHash = Uri.encode("#");
    i.setData(Uri.parse("tel:"+"*100"+encodedHash));

    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    startActivity(i);

用%23替换#可以解决您的问题

There is an important difference between MMI and USSD codes. MMI 和 USSD 代码之间有一个重要的区别。 USSD are executed as soon as the final "#" is entered while MMI codes require a click on the "Call" button.输入最后的“#”后立即执行 USSD,而 MMI 代码需要单击“调用”按钮。

IMPORTANT: In all cases, "#" must be changed to its "%23" ASCII value.重要提示:在所有情况下,“#”都必须更改为其“%23”ASCII 值。

1- MMI codes work with the android.intent.action.DIAL action. 1- MMI 代码与android.intent.action.DIAL操作一起使用。 Here is a Command line example for MMI code *#43#:这是 MMI 代码 *#43# 的命令行示例:

    adb shell am start -a android.intent.action.CALL -d tel:*%2343%23

Will trigger interaction between device and network to report Call waiting status and display the toast "Call Waiting / The service is activated" (or.. is not..).将触发设备和网络之间的交互以报告呼叫等待状态并显示吐司“呼叫等待/服务已激活”(或.. is not..)。

In your code;在您的代码中; something like this will work:像这样的东西会起作用:

    DeviceManipulations.call(phoneNumber.replace("#", "%23"));

2- USSD fail when used with CALL action. 2- 与 CALL 操作一起使用时,USSD 失败。 Use android.intent.action.DIAL .使用android.intent.action.DIAL Plus, it takes a few tricks:另外,它需要一些技巧:

With command line, you must put the code between double quotes .使用命令行,您必须将代码放在双引号之间。 Example for MMI code *#06#: MMI 代码示例 *#06#:

    adb shell am start -a android.intent.action.DIAL -d tel:"*%2306%23"

This displays the Device Information popup.这将显示设备信息弹出窗口。

With my DeviceManipulations code, using DIAL with "*%2306%23" leaves the dialer opened with the code but the execution does not start.使用我的DeviceManipulations代码,将 DIAL 与“*%2306%23”一起使用会使拨号程序随代码打开,但不会开始执行。 Workaround is to do it in two parts: DIAL without the last "#":解决方法是分两部分进行: DIAL 没有最后一个“#”:

    int intlong = codeUSSD.length();
    codeUSSD = codeUSSD.substring(0, (intlong-1));
    DeviceManipulations.dial(codeUSSD.replace("#", "%23"));

.. followed with "input keyevent" for the last "#": .. 后跟最后一个“#”的“input keyevent”:

    DeviceManipulations.customExec("adb shell input keyevent 18");

I suppose that sending every single caracter with "intput keyevent" method would work best but the above is a shortcut.我想用“intput keyevent”方法发送每个字符效果最好,但上面是一个捷径。

Note: The "input keyevent 18" does not trigger action with Samsung devices.注意:“输入 keyevent 18”不会触发三星设备的操作。 Those have a different dialer than Google's.这些拨号器与谷歌的拨号器不同。 I have to use an Appium interaction with those.我必须使用 Appium 与这些交互。

The short answer for the question is:这个问题的简短答案是:

"#" must be changed to its "%23" ASCII value. “#”必须更改为其“%23”ASCII 值。

See my detailed answer for more;)有关更多信息,请参阅我的详细答案;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM