简体   繁体   English

在 Android 中没有得到 USSD 代码的响应

[英]Not Getting Response of USSD Code in Android

I want to dial and get the dialed USSD code response.我想拨打并获得拨打的 USSD 代码响应。 Here is my code.这是我的代码。 but when I run it doesn't show any response on the toast.但是当我运行时,它在吐司上没有显示任何响应。

private void ussdResponse(String completeCode) {

    TelephonyManager manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

    if (checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED || checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CALL_PHONE}, requestCode);
        ActivityCompat.requestPermissions(MainActivity.this , new String[]{Manifest.permission.READ_PHONE_STATE},requestCode);
        return;
    }

    manager.sendUssdRequest(completeCode, new TelephonyManager.UssdResponseCallback() {
        @Override
        public void onReceiveUssdResponse(TelephonyManager telephonyManager, String request, CharSequence response) {

            super.onReceiveUssdResponse(telephonyManager, request, response);

            Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_SHORT).show();
            Toast.makeText(MainActivity.this, "USSD Result"+response.toString(), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onReceiveUssdResponseFailed(TelephonyManager telephonyManager, String request, int failureCode) {

            super.onReceiveUssdResponseFailed(telephonyManager, request, failureCode);
            Toast.makeText(MainActivity.this, "Failed", Toast.LENGTH_SHORT).show();
            Toast.makeText(MainActivity.this, "USSD Response Failed.", Toast.LENGTH_SHORT).show();
        }

    }, new Handler());
}

compleCode contains the USSD Code. compleCode代码包含 USSD 代码。 But the Toast shows Nothing.但是吐司什么也没显示。 can any one please find me the solution.?任何人都可以找到我的解决方案。? Or is there any other way to get the dialed USSD response in my app?或者有没有其他方法可以在我的应用程序中获得拨打的 USSD 响应?

I found the answer myself.我自己找到了答案。 I Used this Api to resolve the problem.我用这个 Api 来解决这个问题。 https://github.com/romellfudi/VoIpUSSD https://github.com/romellfudi/VoIpUSSD

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

HashMap map = new HashMap<>();
                        map.put("KEY_LOGIN",new HashSet<>(Arrays.asList("espere", "waiting", "loading", "esperando")));
                        map.put("KEY_ERROR",new HashSet<>(Arrays.asList("problema", "problem", "error", "null")));

                        final USSDApi ussdApi = USSDController.getInstance(MainActivity.this);
                        ussdApi.callUSSDInvoke("*786#", map, new USSDController.CallbackInvoke() {
                            @Override
                            public void responseInvoke(String message) {
                                // message has the response string data
                                String dataToSend = "data";// <- send "data" into USSD's input text
                                ussdApi.send(dataToSend,new USSDController.CallbackMessage(){
                                    @Override
                                    public void responseMessage(String message) {
                                        // message has the response string data from USSD
                                        Log.d("message", message);
                                    }
                                });
                            }

                            @Override
                            public void over(String message) {
                                // message has the response string data from USSD or error
                                // response no have input text, NOT SEND ANY DATA
                            }
                        });

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

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