Getting permission not granted in GingerBread - android

I am using following function to check whether read from external storage permission has been granted or not.
public static boolean checkWritePermissions(Context context)
{ String permission = "android.permission.READ_EXTERNAL_STORAGE";
int res = context.checkCallingOrSelfPermission(permission);
return (res==PackageManager.PERMISSION_GRANTED);
}
The function is working correctly for post GingerBread devices, however for GingerBread devices the returned value is false. Ignoring the function returned value shows that permission has been granted. Is there any alternative for GingerBread devices.
P.S.: The application isn't using Support Library so new permission methods aren't being used.

Related

What permission do we need to use instead of WRITE_EXTERNAL_STORAGE in Android 13 app on Android 13 device?

What permission do we need to use instead of WRITE_EXTERNAL_STORAGE in Android 13 app on Android 13 device? I have read through the documentation but not able to get what permission we need to use. The function which needs this is a photo picker which access the images, before it used to ask for permission on Android 12, but once the app was upgraded to Android 13 and used on an Android 13 app, the photo picker stopped working. It uses the permission WRITE_EXTERNAL_STORAGE which is not required anymore. But what needs to be used instead of this?
The function is from a library - react-native-image-crop-picker
#ReactMethod
public void openPicker(final ReadableMap options, final Promise promise) {
final Activity activity = getCurrentActivity();
if (activity == null) {
promise.reject(E_ACTIVITY_DOES_NOT_EXIST, "Activity doesn't exist");
return;
}
setConfiguration(options);
resultCollector.setup(promise, multiple);
initiatePicker(activity);
permissionsCheck(activity, promise, Collections.singletonList(Manifest.permission.WRITE_EXTERNAL_STORAGE), new Callable<Void>() {
#Override
public Void call() {
return null;
}
});
}
Use react-native-permissions for managing the permissions.
The docs are quite simple, kindly go through this.
Some permission changes were required for this in the react-native-image-cropper library - https://github.com/ivpusic/react-native-image-crop-picker/pull/1852

How to check if user has given camera or location permissions (android) UNITY

I really struggle with this since a while :( as I need an solution that works within UNITY3D.
I need to check if the user has given the permission to access the Android device camera (and location on a second level).
Normally the app start by asking for this permissions at launch, but if the user denies the access for the camera I need to know and check that later.
Otherwise the user could hit the camera UI button I made and try to access the camera via webcamtexture... and that leads into a crash of the app.
Since Android API 23 you cannot ignore or already grant permissions by changing the android manifest like I tried after reading several posts about that.
Thank's to everyone who has an idea to solve this.
Check this library: https://github.com/sanukin39/UniAndroidPermission
In that library I got these methods to check and request Permission.
public static void requestPermission(String permissionStr){
if(!hasPermission(permissionStr)) {
UnityPlayer.currentActivity.requestPermissions(new String[]{permissionStr}, 0);
}
}
public static boolean hasPermission(String permissionStr) {
if(Build.VERSION.SDK_INT < 23) {
return true;
}
Context context = UnityPlayer.currentActivity.getApplicationContext();
return context.checkCallingOrSelfPermission(permissionStr) == PackageManager.PERMISSION_GRANTED;
}
Hope it helps:)

Android Marshmallow permission model on OS 4.0 READ_EXTERNAL_STORAGE permission always not granted

I have a problem when running my app on Android OS 4.0 and requesting READ_EXTERNAL_STORAGE permission with:
ActivityCompat.requestPermissions(ctx, requestedPermissions, requestCode);
I always get on the callback
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions,
#NonNull int[] grantResults) {
grantResults != PackageManager.PERMISSION_GRANTED
Checking the permission with ActivityCompat.checkSelfPermission is always returning permissionDenied.
It works well on OS 6.0 by requesting the permission with system dialog.
Android OS 4.x excepted the 4.0 the permission is always granted.
OS 4.0 the other permissions (Camera,Calendar,Contact,Phone) are behaving well except the READ_EXTERNAL_STORAGE causing this issue.
Maybe an OS issue?
What ActivityCompat.requestPermissions() does is:
call through to the real requestPermissions() if you are on Android 6.0+, or
use PackageManager to see if you hold the requested permissions on older versions of Android
The problem with READ_EXTERNAL_STORAGE is that it was added in API Level 16 (Android 4.1). You cannot hold it on older versions of Android than that, for the simple reason that it did not exist.
Either:
Set your minSdkVersion to 16, or
Put your own logic in to handle this case, recognizing that READ_EXTERNAL_STORAGE is irrelevant prior to API Level 16
I discovered this issue when dealing with FOREGROUND_SERVICE on Android 8.0. My solution unfortunately depends on the exception handling, but it does not require dealing with the API level the permission is supported from. You can check if permission exists on current API level with this method:
private boolean permissionExistsOnCurrentApiLevel(String permission) {
try {
getPackageManager().getPermissionInfo(permission, PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
return true;
}
With this method you can implement you own version of ContextCompat.checkSelfPermission where all non-existing permission are automatically considered to be granted:
private int myCheckSelfPermission(#NonNull Context context, #NonNull String permission) {
if(!permissionExistsOnCurrentApiLevel(permission)) {
return PackageManager.PERMISSION_GRANTED;
}
return ContextCompat.checkSelfPermission(this, permission);
}

Is ACCESS_COARSE_LOCATION necessary if the user has already granted ACCESS_FINE_LOCATION?

I am updating my app to work with the new Android Marshmallow permission framework and it looks like it's enough for the user to grant the ACCESS_FINE_LOCATION permission at runtime for the app to work fine. This is what I do:
public static final String[] runtimePermissions = { permission.ACCESS_FINE_LOCATION };
public static final int LOCATION_PERMISSION_IDENTIFIER = 1;
and further down the class:
public static boolean checkConnectionPermission(final Context context) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
if (context.checkSelfPermission(permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
return true;
}
else {
((Activity) context).requestPermissions(runtimePermissions,
LOCATION_PERMISSION_IDENTIFIER);
return false;
}
}
// since in API levels below M the permission is granted on
// installation,
// it is considered a given that the permission has been granted since
// the
// app is running. So we return true by default
else {
return true;
}
}
I am just concerned that I am overlooking something that could cause trouble in the future (the app is near-production) with Security Exception(s).
I guess my ultimate question is: does granting FINE_LOCATION somehow auto-grant COARSE_LOCATION too?
Sort of already answered here.
If I have ACCESS_FINE_LOCATION already, can I omit ACCESS_COARSE_LOCATION?
Some additional information, you should look at permission group.
https://developer.android.com/preview/features/runtime-permissions.html
They are in the same permission group. If you really want to play safe, just include both in your manifest, and request them on need. It would be transparent to user.
According to this blog post, if you have specified both in the manifest and the user has granted you one, then when you ask for the other it will be automatically granted (since they're both in the same permission group).
That means that if you have been granted COARSE_LOCATION and then ask for FINE_LOCATION you can get it without the user being prompted, but the catch is that you still have to specify both in the manifest.
Apps can actually register for two types of location updates. Fine grained, which uses the Global Positioning System to get the device’s location accurate to within a few meters, vs coarse-grained, which uses the Wifi, Cell towers and other data available to the device to get a rough (accurate to 10s of meters) location of the device.
Choice is yours.

Checking permission of write to external storage in Android application

Normal way to do that is checking whether the manifest uses WRITE_EXTERNAL_STORAGE permission:
String permission = "android.permission.WRITE_EXTERNAL_STORAGE";
int res = context.checkCallingOrSelfPermission(permission);
return (res == PackageManager.PERMISSION_GRANTED);
My question is in about using canWrite() method.Docs say:
public boolean canWrite ()
Added in API level 1
Indicates whether the
current context is allowed to write to this file.
So we can use this method to check permission like this:
Environment.getExternalStorageDirectory().canWrite();
This way seems to be simpler than first way and also does not need to use Context.Also we can use same to check read permission.But is this a good way to check those?Also is it a good way to check if manifest uses read/write permissions?

Categories

Resources