0

Once dialer in opened using ACTION_DIAL through code, I can't navigate back to my application. It is a device specific problem and occurring in my one plus devices. Here's my code snippet:

Intent intent = new Intent(Intent.ACTION_DIAL);

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

startActivityForResult(intent, AppConstants.CALL_NOW_ACTION);
ADM
  • 20,406
  • 11
  • 52
  • 83
  • Try this: https://stackoverflow.com/a/5273295/7746134 – Saurabh Thorat Feb 15 '19 at 06:23
  • This is not helpful for me as I am not using or want to use ACTION_CALL . My code will just open the dialer showing the passed number. It'll not call automatically so checking call_state won't help me. – Srishti Negi Feb 15 '19 at 06:42

2 Answers2

0

Try This one will help you:-

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);
                   }

Or

2 . Call placeCall() method at clickListener.

  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));
                    }
                }
            }
Alok Singh
  • 640
  • 4
  • 14
0

Below code is help for kotlin:

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

Below code for Java

    Intent intent = new Intent(Intent.ACTION_DIAL);

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

startActivity(intent);
Neil
  • 93
  • 3
  • 8