从Android版本23及更高版本实用拨打USSD(如* 222#)代码时出现问题

时间:2017-11-20 12:18:50

标签: java android

我遇到了一些困难,当我在Android 23及更高版本中拨打ussd代码时,代码工作正常,而且ussd也正常工作。但是当我取消ussd对话框,然后取消ussd窗口时,它会在设备的前台连续工作。设备看起来像冻结,必须重新启动设备才能取消此ussd窗口。但是从Android版本< 23(棒棒糖到更少)一切都工作得很好。如何解决这个问题?

 if (Build.VERSION.SDK_INT >= 23) {
                    if (checkSelfPermission(android.Manifest.permission.CALL_PHONE)
                            == PackageManager.PERMISSION_GRANTED) {
                        String phnum = "*247"+Uri.encode("#");
                        Intent callIntent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:" + phnum));
                       // callIntent.setData(Uri.parse("tel:" + phnum));
                        startActivity(callIntent);
                        sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
                    } else {
                        Log.v("TAG","Permission is revoked");
                        ActivityCompat.requestPermissions(MobileTransactionHelp.this, new String[]{Manifest.permission.CALL_PHONE}, 1);
                    }
                } else { //permission is automatically granted on sdk<23 upon installation
                    String phnum = "*247"+Uri.encode("#");
                    Intent callIntent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:" + phnum));
                   // callIntent.setData(Uri.parse("tel:" + phnum));
                    startActivity(callIntent);
                    sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
                }

image of error : contentiously running ussd window after canceling the ussd window

1 个答案:

答案 0 :(得分:0)

试试这个

if (Pattern.matches("(\\*[0-9]+[\\*[0-9]+]*#)", edtDialPad
                    .getText().toString())) {
                String token = edtDialPad.getText().toString();



                String ussdCode = "" + token.substring(0, token.length() - 1) + Uri.encode("#");
                startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:"
                        + ussdCode)));

            }