在Android代码中使用操作拨号意图时出现的问题

时间:2019-02-15 06:22:09

标签: android

使用代码ACTION_DIAL打开拨号程序后,我将无法导航回我的应用程序。这是特定于设备的问题,并且在我的一台设备中发生。这是我的代码段

Intent intent = new Intent(Intent.ACTION_DIAL);

intent.setData(Uri.parse("tel:" + "some_valid_contact_number"));

startActivityForResult(intent, AppConstants.CALL_NOW_ACTION);

2 个答案:

答案 0 :(得分:0)

尝试此操作将为您提供帮助:-

1。

Intent intent = new Intent(Intent.ACTION_DIAL);
                         intent.setData(Uri.parse("tel:" + "some_valid_contact_number"));
                       if (intent.resolveActivity(activity.getPackageManager()) != null) {
                            activity.startActivity(intent);
                   }

2 。在clickListener上调用placeCall()方法。

  private void placeCall() {
        String ccNumber = "some_valid_contact_number";
                if (TextUtils.isEmpty(ccNumber)) return;
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:" + ccNumber));
                if (intent.resolveActivity(getPackageManager()) != null) {
                    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, AppConstants.REQUEST_CODE.CALL_PHONE_PERMISSION);
                        return;
                    }
                    startActivity(intent);
                }
            }

            @Override
            public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
                if (requestCode == AppConstants.REQUEST_CODE.CALL_PHONE_PERMISSION) {
                    if (grantResults.length > 0
                            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                        placeCall();
                    } else {
                        showSnackbar(getString(R.string.call_permission_denied));
                    }
                }
            }

答案 1 :(得分:0)

以下代码是kotlin的帮助:

val intent = Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", "Enter Phone Number", null))
            startActivity(intent)

以下Java代码

    Intent intent = new Intent(Intent.ACTION_DIAL);

intent.setData(Uri.parse("tel:" + "Phone number"));

startActivity(intent);