androidandroid-phone-call

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 calling button for android Marshmallow?

This is the code I used for the calling button :

public void button(View v) {

        String number = "12354656";
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:" + number));


        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

            return;
        }
        startActivity(intent);

}

Solution

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