5

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?

Vishal Jadav
  • 924
  • 9
  • 11

2 Answers2

2

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.

arghtype
  • 4,376
  • 11
  • 45
  • 60
TysonSubba
  • 1,362
  • 2
  • 12
  • 16
  • I know that. But i have used Dexter library for permission model. Then why i have to check Self permission and another thing is that if i use `Intent.ACTION_DIAL` instead of `Intent.ACTION_CALL` then its not shows warning. So i don't understand what should i do? – Vishal Jadav Jan 18 '17 at 10:18
  • Check my edited answer.. Intent.ACTION_DIAL will not make a call directly ..it brings up the dialer with the number you have inserted..That's why Intent.ACTION_DIAL doesn't need the permission as user confirms to make a call manually..... – TysonSubba Jan 18 '17 at 10:34
  • I want to check PHONE_CALL permission by only Dexter. Is it possible or not? and if possible then how? – Vishal Jadav Jan 18 '17 at 10:45
  • yes , you can lower your targetedsdkversion to below 23.. but for sdk>23 you should check it – TysonSubba Jan 18 '17 at 11:01
0

I had a similar issue. For me, my justification was showing when I tried to make a call. I added the manifest tag:

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

Not sure why I had to do this in addition to using Dexter runtime checking, but it solved my issue.

gyleg5
  • 144
  • 1
  • 2
  • 11