Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHONE_CALL permission not working in Dexter

I have implemented Dexter in my app. It is work fine for CAMERA,EXTERNAL STORAGE and INTERNAL STORAGE permission. I want to call with PHONE_CALL permission with Dexter. When i call intent for phone call like this:

Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + strNum));
startActivity(callIntent);

then startActivity shows warning Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException less... (Ctrl+F1)

I don't understand that i have implement Dexter then why startActivity want self permission?

like image 688
Vishal Jadav Avatar asked Oct 29 '22 13:10

Vishal Jadav


1 Answers

For API 23+ you should check for permission as:

if (mContext.checkSelfPermission(Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
    Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + strNum));
    startActivity(callIntent):   
}

Intent.ACTION_CALL intent, which requires a permission, namely the android.permission.CALL_PHONE one. But for sdk>=23 you need to check in runtime with Manifest.permission.CALL_PHONE. It is for targetedsdkversion 23 and above.

If you lower your targetedsdkversion below 23 then you don't need this persmission and Intent.ACTION_CALL will work fine.

like image 180
TysonSubba Avatar answered Nov 09 '22 15:11

TysonSubba