Skip to content Skip to sidebar Skip to footer

How To Make A Call Directly?

when I use this code, first comes the dial pad screen with this number. Intent dialintnt = new Intent(Intent.ACTION_DIAL,Uri.parse('tel:911')); startActivityForResult(dialintnt, CA

Solution 1:

It's not possible. This is for user protection.

Solution 2:

It's been a long time. But may help someone else. If you want to call directly, you should use requestPermissions method.

1. Add this line to your manifest file:

<uses-permissionandroid:name="android.permission.CALL_PHONE" />

2. Define a class variable in the activity class:

privatestatic Intent phoneCallIntent; //If use don't need a member variable is good to use a static variable for memory performance.

3. Add these lines to the onCreate method of the activity:

finalStringpermissionToCall= Manifest.permission.CALL_PHONE;
//Assume that you have a phone icon.
(findViewById(R.id.menuBarPhone)).setOnClickListener(newOnClickListener(){
    publicvoidonClick(View view) {
        phoneCallIntent = newIntent(Intent.ACTION_CALL);
        phoneCallIntent.setData(Uri.parse(getString(R.string.callNumber))); //Uri.parse("tel:your number")if (ActivityCompat.checkSelfPermission(MainFrame.this, permissionToCall) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(MainFrame.this, newString[]{permissionToCall}, 1);
            return;
        }
        startActivity(phoneCallIntent);
    }
});

4. And for making a call immediately after clicking on Allow button, override onRequestPermissionsResult method:

@OverridepublicvoidonRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNullint[] grantResults){
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if(requestCode == 1){
        finalintpermissionsLength= permissions.length;
        for (inti=0; i < permissionsLength; i++) {
            if(grantResults[i] == PackageManager.PERMISSION_GRANTED){
                startActivity(phoneCallIntent);
            }
        }
    }

When a user give the permission, next time there will be no dialogue box and call will be make directly.

Solution 3:

See the answer

You will need add CALL_PHONE and CALL_PRIVILEGED permissions to manifest file.

Then the number can be called using:

UricallUri= Uri.parse("tel://911");
IntentcallIntent=newIntent(Intent.ACTION_CALL,callUri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivity(callIntent);

Solution 4:

Just change ACTION_DIAL to ACTION_CALL. Like this:

Intentdialintnt=newIntent(Intent.ACTION_CALL,Uri.parse("tel:911"));
startActivityForResult(dialintnt, CALLING);

Solution 5:

Try this:

IntentcallIntent=newIntent(Intent.ACTION_CALL);
   callIntent.setData(Uri.parse("tel:" +phone_number));
   startActivity(callIntent);

Post a Comment for "How To Make A Call Directly?"