Skip to content Skip to sidebar Skip to footer

How To Make A Phone Call Button In Android For Marshmallow

I'm trying to create a calling button in Android. I created one and it works in all kind of Android device but it's not working on Marshmallow. I don't know why. How to create a c

Solution 1:

You'll need to enable permission for your app in the phone settings. Look under permissions in settings

Solution 2:

The issue is probably related to Runtime Permissions introduced in Android 6.0.

You can try this:

if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, newString[]{Manifest.permission.CALL_PHONE},REQUEST_PHONE_CALL);
}
else
{
    startActivity(intent);
}

Solution 3:

You have to try this...

put in your android manifest

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

get runtime permission for make phone call(Android API version 23 and above)

privatestatic final int REQUEST_PERMISSION_CALL = 111;

if (ContextCompat.checkSelfPermission(getActivity(),
                Manifest.permission.CALL_PHONE)
                != PackageManager.PERMISSION_GRANTED) {
            if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                    Manifest.permission.CALL_PHONE)) {
                ActivityCompat.requestPermissions(this, getString(R.string.app_need_call_permission),
                        REQUEST_PERMISSION_CALL, Manifest.permission.CALL_PHONE);
            } else {
                ActivityCompat.requestPermissions(this, getString(R.string.app_need_call_permission),
                        REQUEST_PERMISSION_CALL, Manifest.permission.CALL_PHONE);
            }
        }

you will get permission response on

@Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == REQUEST_PERMISSION_CALL) {
            // put your code here to make call
        }
    }

then you have to make your phone call

Urinumber= Uri.parse("tel:123456789");
IntentcallIntent=newIntent(Intent.ACTION_DIAL, number);
startActivity(callIntent);

for more info https://developer.android.com/training/permissions/requesting.html

Hope this will help you.

Post a Comment for "How To Make A Phone Call Button In Android For Marshmallow"