How to ask permission to make phone call from Android from Android version Marshmallow onwards?

前端 未结 6 1902
北海茫月
北海茫月 2020-12-31 03:33

I am trying to make a phone call from Android, and I\'ve set run time permissions as well. And it asks whether to allow making phone calls. But when I press allow, the app c

6条回答
  •  無奈伤痛
    2020-12-31 03:51

    You need to create your Intent in onRequestPermissionsResult

    
    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case REQUEST_PHONE_CALL: {
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "+918511812660"));
                    startActivity(intent);
                }
                else
                {
    
                }
                return;
            }
        }
    } 

提交回复
热议问题