PHONE_CALL permission not working in Dexter - android

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?

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.

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.

Related

Unable to create a shortcut for calling a number on Android N

This is an example of a code for creating a direct shortcut that calls a specific number and which works on Android M and below.
public void installShortcutGetId(){
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"MyCallShortcut");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_CALL, Uri.parse("tel:77777777")));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, android.R.drawable.sym_def_app_icon));
context.sendBroadcast(intent);
}
The same code doesn't work anymore on Android N, I can see in the logcat the following:
/com.android.launcher3 E/InstallShortcutReceiver: Ignoring malicious intent tel:77777777#Intent;action=android.intent.action.CALL;end
If I change ACTION_CALL to ACTION_DIAL, it works on Android N but that's not what I am looking for. I am looking for a way to make a direct call through the shortcut.
In terms of permissions, I have these 2 included and CALL_PHONE requested at run-time.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.CALL_PHONE" />
Just because your app has the CALL_PHONE permission doesn't mean the launcher has that permission: that's why your shortcut cannot be created.
You could instead create a shortcut to an empty activity of your own and start the ACTION_CALL Intent from that activity.

Is it possible to make a direct call?

We know you can open a call application using this code:
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:0377778888")));
Is it possible to make a direct call without having to go through the default application of the device?
This code snippet makes the direct call:
// Check the SDK version and whether the permission is already granted or not.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, PERMISSIONS_REQUEST_PHONE_CALL);
} else {
//Open call function
String phone = "7769942159";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:+91" + phone));
startActivity(intent);
}
Use this permission in manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
Yes, You can do it by just replacing Intent.ACTION_DIAL with Intent.ACTION_CALL in your code.
And you must need the CALL permission to the app.
For below Marshmallow devices you can make it by simply placing the below line in your manifest under manifest tag
<uses-permission android:name="android.permission.CALL_PHONE" />.
But for Marshmallow or above OS devices you need to declare the permission in manifest like below
<uses-permission-sdk-23 android:name="android.permission.CALL_PHONE" />
And you need to ask the user Runtime permission for CALL_PHONE access.
To request permission
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.CALL_PHPNE})
To check permission
ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.CALL_PHONE)
!= PackageManager.PERMISSION_GRANTED
For more info https://developer.android.com/training/permissions/requesting.html
You are looking for ACTION_CALL: https://developer.android.com/reference/android/content/Intent.html
Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phno);
startActivity(intent);
Android Manifest
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

Android Intent Calling

I tried to make a call when I click on Android Mobile field with this code
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+contactNo));
startActivity(callIntent);
And added these in AndroidManifest.xml
<uses-permission android:name="packagename.permission.C2D_MESSAGE"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
And finally I am getting **java.lang.SecurityException** exception.
Why it Happens? and What is the Correct Procedure to Make a Call when click on Contact field?
use Intent.ACTION_DIAL instead of Intent.ACTION_CALL
And action_dial does not need permission, and it will show dialed phone number to user on dialer and then it will be users wish to place a call or not. This will be better approach to give user a control of what they wants to do.
hope that will help you
In order to use Intent.ACTION_CALL you have to add a permission to your manifest.
Add this permission to your manifest and it should be ok
<uses-permission android:name="android.permission.CALL_PHONE"/>

Android M permission dialog not showing

I'm currently trying to adapt my application to the new permissions model of Android M.
I'm collecting all the permissions I require, then run
Log.i("Permissions", "Requesting permissions: " + permissions);
requestPermissions(requiredPermissions.toArray(new String[requiredPermissions.size()]), requestCodeForPermissions);
requiredPermissions holds the permissions I need like android.permission.WRITE_EXTERNAL_STORAGE.
That routine is definitely executed as I have the Log line in the logcat:
08-07 12:52:46.469: I/Permissions(1674): Requesting permissions: android.permission.RECEIVE_BOOT_COMPLETED; android.permission.WRITE_EXTERNAL_STORAGE
But the permissions dialog never shows, let alone is onRequestPermissionsResult() called.
What am I doing wrong? Based on some tutorials I found I'm not missing anything.
I only have the emulator for testing, no physical device. This is the about screen from settings:
Image
It might be worth mentioning something else: If I try to open the overview of installed apps from the home screen I only get launcher3 has exited. I'm not sure if that might be related.
Does anybody have an idea why it's not showing?
I experienced the same issue but later I realized I forgot to add the permission to the manifest file. After adding the uses-permission tag, the system showed the dialog. Maybe helps someone.
The original answer helped me.
I fixed by adding tools:remove="android:maxSdkVersion" like this:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"/>
I experienced the same issue because I was using the negative value as a REQUEST_CODE.
requestPermissions(new String[]{android.Manifest.permission.CAMERA}, -1)
After using positive value, the system showed the dialog.
Hope it helps someone.
Based on the comment from Hilal (thanks a lot!):
In my case my app is indeed using tabhost and the permissions were requested from an Activity inside the tabhost. After starting a separate activity that requests the permissions it is working.
I just had the same problem.
My issue was that I wrote the permission at the wrong place in the manifest.
Make sure the uses permission is outside of application:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gms.samples.vision.face.photo"
android:installLocation="auto"
android:versionCode="1"
android:versionName="1" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:hardwareAccelerated="true"
android:label="FacePhotoDemo"
android:allowBackup="true"
android:icon="#drawable/icon">
add
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
in AndroidManifest.xml
Note : The Permission which you want to get. Eg: android.permission.ACCESS_FINE_LOCATION etc.
I have also come across a situation where the permission dialog doesn't appear or the application crashes when using the <uses-permission-sdk23> element, however the cause appears to be a system bug on current 6.0 devices:
https://code.google.com/p/android/issues/detail?id=189841
Crash exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity}: java.lang.NullPointerException: Attempt to get length of null array
I have the same issue and the problem is solved after adding the shouldShowRequestPermissionRationale like this:
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
} else {
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
}
To add to #shanraisshan's answer, the REQUEST_CODE actually has to be greater than 0, not just non-negative.
In our code, it was a simple spelling mistake.
We had:
<uses-permission android:name="android.permission.ACCESS_COURSE_LOCATION" />
It should be:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
I was doing two calls to requestPermissions(), one right after the other. This error message appeared in Logcat (note the misspelling on "request"):
Can reqeust only one set of permissions at a time
requestPermissions() is actually designed to take multiple requests at once; that's what the String array is for.
In my case, the permission I was requesting (WRITE_SETTINGS) was more special and required Settings Activity to launch. So dialog was not showing up.
I had to get its permission using the following code:
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + context.getPackageName()));
startActivityForResult(intent, CODE_WRITE_SETTINGS_PERMISSION);
Yet another cause for not getting the permission dialog to show when requesting a dangerous permission...
I had to do Build -> Clean Project and then Build -> Rebuild Project. I guess Android Studio didn't pick up on the changes I made in the manifest.
I had a similar issue caused by the wrong case of the permission constant in the manifest, I was using read_contacts in lower case:
<uses-permission android:name="android.permission.read_contacts" />
After changing read_contacts to uppercase it started working as expected
<uses-permission android:name="android.permission.READ_CONTACTS" />
Permissions are organised into categories so non-critical ones are granted without the dialog being shown.
I found this the hard way with internet permission, if you're having this issue then changing to a critical permission such as read_contacts will allow you to test your flow and reveal whether the issue is the permission being non-critical or something else.
Normal protection permissions are listed here
In the manifest, I changed
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
to
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
Maybe that helps.
Add permission in the manifest file as well.
If anyone of you guys has an application that changes/modifies WRITE_SETTINGS and are facing this issue. Check out CommonsWare's Answer to WRITE_SETTINGS Ambiguity
I was facing this issue for 2 weeks and later realised that this issue was due to the fact that requestPermissions doesn't work for requesting WRITE_SETTINGS permission.
Hope this helps :D
In my case I had requested "ACCESS_COARSE_LOCATION" in my manifest file and then request for "ACCESS_FINE_LOCATION" permission in code that's why the Permission Dialog was not opening.
After searching a while it appears it is required to set the value compileSdkVersion to "android-MNC" or as of today to 23. That requires the Gradle build system which then seems to require Android Studio.
At least I couldn't find a single manual about how to set it outside the gradle files.
I did all the things said in above answers but still dialog was not showing and then I changed targetSdkVersion to 23 in gradle and it appeared . Hope this helps someone
#Override
public final void validateRequestPermissionsRequestCode(int requestCode) {
// We use 16 bits of the request code to encode the fragment id when
// requesting permissions from a fragment. Hence, requestPermissions()
// should validate the code against that but we cannot override it as we
// can not then call super and also the ActivityCompat would call back to
// this override. To handle this we use dependency inversion where we are
// the validator of request codes when requesting permissions in
// ActivityCompat.
if (!mRequestedPermissionsFromFragment
&& requestCode != -1 && (requestCode & 0xffff0000) != 0) {
throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");
}
}
Had the same issue. Later I realized that we have to declare each and every permission in manifest (even if one is a subclass of another).
In my case I declared
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
in my manifest and was trying to access user's coarse location.
ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
Fixed the problem by adding coarse permission as well in manifest.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Set your targetSdkVersion to 22.
had the same (i guess) problem and the solution was removing
import <app package>.Manifest;
autoimported by Android Studio at the top of the file and substitute it with
import android.Manifest;
and started working
In my case the solution is the string itself
android.permission.READ_CONTACTS
I did Manifest.permission.READ_CONTACTS which caused silence error (Noting show on the screen).
Make sure that this is correct
My Android targetSDK version is 28.
I don't see any pop ups shown to user requesting for permission which are listed in android Manifest.xml as .
During both installation, installing .apk using USB and installing app from google play store.
So I added below code in my activity it will ask user permission during runtime
ActivityCompat.requestPermissions(MyActivity.this,
new String[]{Manifest.permission.READ_PHONE_STATE}, 1);
I was requesting permission through code, but had missed adding the <uses-permission ..> tag in manifest !
Change the final constant value to 1.
private static final int REQUEST_PERMISSION_WRITE = 1;
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},REQUEST_PERMISSION_WRITE);

android.permission.CALL_PHONE for tablets

I am developing an app and in the manifest I have:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
When I click on the button to execute this code:
Intent intentcall = new Intent();
intentcall.setAction(Intent.ACTION_CALL);
intentcall.setData(Uri.parse("tel:" + phonenumber)); // set the Uri
startActivity(intentcall);
It will run fine on phones, and on tablets it pops up with a display where you can view or add the number to contacts. However, if I keep the permission in the manifest, it isn't available for tablets in the market. How can I keep the code behavior and still have it display in the market for tablets as well as phones?
In the AndroidManifest you need:
<uses-feature android:name="android.hardware.telephony" android:required="false" />
The CALL_PHONE permission implies telephony is required, but if you specify that is not you won't be filtered.
Try to use Intent.ACTION_DIAL instead Intent.ACTION_CALL.
For example:
try {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone_number));
startActivity(intent);
} catch (Exception e) {
//TODO smth
}
And in this case you can completely remove these tags from AndroidManifest.xml:
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-feature android:name="android.hardware.telephony" android:required="false" />
Regarding "uses-feature" and it crashing - are you checking that telephony is available before actually making the call? It might be you need to do that extra step for the case when the app is on tablets. All you are saying in the manifest is that the feature is not required. It probably relies on you to actually implement the logic around that.
Instead of adding a user with the ACTION_CALL identifier, change it to ACTION_INSERT_OR_EDIT.
You'll need these permissions too, instead of the CALL_PHONE permission:
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>
Take a look at this related question:
can't find app on market
From google docs:
Declared elements are informational only, meaning that
the Android system itself does not check for matching feature support
on the device before installing an application
usage is only for google play

Categories

Resources