Forum Xamarin.Android

Android 6.0 Api 23 and Android 7.1 API 25 permissions always returning Permission Granted

WhitchurchMuthumaniWhitchurchMuthumani USMember ✭✭
edited July 2017 in Xamarin.Android

I am currently trying to implement the permission checks, to handle API > 23 on Android 6.0 and beyond.
I have tried testing my code (very simple) to see if it will return PERMISSION_GRANTED or PERMISSION_DENIED, when i toggle the apps Camera permission
It has not worked for both Android 6.0 API 23 and Android 7.1 API 25

Here is my code
//var thisActivity = Forms.Context as MainActivity; --> I tried this too, hoping that maybe I was not passing in the correct context.
Android.Content.PM.Permission permissionCheck = ContextCompat.CheckSelfPermission(Android.App.Application.Context,
Android.Manifest.Permission.Camera);
if(permissionCheck == Android.Content.PM.Permission.Granted)
{
//Device.BeginInvokeOnMainThread(() => Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Info", "Permission granted", "Ok"));
return true;
}
else
{
//I am going to code in the logic for giving the user the option to enable the permission or accept the stats quo here.
//Device.BeginInvokeOnMainThread(() => Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Info", "Permission denied", "Ok"));
return false;
}

Best Answer

  • Accepted Answer

    So the final conclusion that worked for me to anyone reading this post is.
    Use the permission plugin like what Mr.Pearce mentioned
    Set a specific TargetSDKVersion in the manifest, for the permission plugin to start functioning

Answers

  • Mr.PearceMr.Pearce DEMember ✭✭

    have you added the Camera permission into the AndroidManifest?

    You could also try this plugin wich is pretty handy.
    Note: if you want to use the photo permission its "Photos" on ios and "Storage" on android

  • WhitchurchMuthumaniWhitchurchMuthumani USMember ✭✭
    edited July 2017

    @Mr.Pearce Thanks I have downloaded James Monte-mango's sample project that uses the plugin from github, and got it working to test out the permissions.

    • The camera permission is added in the manifest like so:

    Uses-permission android:name="android.permission.CAMERA"

    • However I am now trying to see why using the plugin , is always giving me Permission_Granted. Currently comparing Jame's project against my App's code to see any deltas, or maybe some updated nugets he is using that I am not, that might be causing issues.
  • WhitchurchMuthumaniWhitchurchMuthumani USMember ✭✭
    edited July 2017

    @Mr.Pearce I got it to work in my project.

    • However I don't think it is a good solution.
    • TO get it to work. I had to explicity specify a android:targetSDKVersion = 25.
    • uses-sdk android:minSdkVersion="15" android:targetSdkVersion="25"
    • Before it used to be like this in the manifest: uses-sdk android:minSdkVersion="15"
    • My worry is this is not a good solution. As I do not know if versions between 15 and 25 will be supported if i specify a targetSDK version.

    Thanks

  • WhitchurchMuthumaniWhitchurchMuthumani USMember ✭✭
    Accepted Answer

    So the final conclusion that worked for me to anyone reading this post is.
    Use the permission plugin like what Mr.Pearce mentioned
    Set a specific TargetSDKVersion in the manifest, for the permission plugin to start functioning

  • CarLoOSXCarLoOSX USMember ✭✭

    I'm having the same problem ... any success?

Sign In or Register to comment.