Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

CrossPermissions.Current.RequestPermissionsAsync always returns PermissionStatus.Unknown. #39

Closed
pradeeparutla opened this issue Feb 15, 2017 · 5 comments
Labels

Comments

@pradeeparutla
Copy link

pradeeparutla commented Feb 15, 2017

CrossPermissions.Current.RequestPermissionsAsync always returns PermissionStatus.Unknown.

Bug

Version Number of Plugin: 1.2.1
Device Tested On: Android 6.0 OS
Simulator Tested On:

Expected Behavior

CrossPermissions.Current.RequestPermissionsAsync should return the status as PermissionStatus.Granted.

Actual Behavior

CrossPermissions.Current.RequestPermissionsAsync always returns PermissionStatus.Unknown.

Steps to reproduce the Behavior

Request the permission using the below statement in dependency service in android project.

var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera, Permission.Storage });

cameraStatus = results[Permission.Camera]; //CameraStatus is always returned as PermissionStatus.Unknown

I am using the plugin.currentactivity in android project.

Note: I am writing the above code in custom control and using it later in the actual application.

@pradeeparutla
Copy link
Author

When I check in the code permissionStatus.Unknown is returned in the below scenario. Do I need to do anything in my application for this ? Debug.WriteLine("Unable to detect current Activity or App Context. Please ensure Plugin.CurrentActivity is installed in your Android project and your Application class is registering with Application.IActivityLifecycleCallbacks.")

@jamesmontemagno
Copy link
Owner

Did you do this: https://github.com/jamesmontemagno/PermissionsPlugin#android-specific-in-your-baseactivity-or-mainactivity-for-xamarinforms-add-this-code

When you install this plugin it will also install a file called "MainApplication.cs" into your Android app and that needs to be there.

@pradeeparutla
Copy link
Author

It is now working. Application.cs class is missing from my project. Thankyou James for the reply

@savvaskef
Copy link

savvaskef commented Feb 28, 2020

I had the exact same problem(status=unknown). but no application.cs was added nor a mainapplication.cs when i updated the Mediaplugin and installed PermissionsPlugin.
Being 'creative' i added two things mentione on the documentation on the link you provided to MainActivity.cs (it's an another developer's xamarin app ia am implementing the android version) Speicifically i added
1)
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
on the OnRequestPermissionsResult (maybe i need to mention that there also exists a Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
on the same method)
and 2)
Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, savedInstanceState);
on the protected override void OnCreate(Bundle savedInstanceState) method.

Now the status=unkwown no longer waits but the code still has problems.namely the
await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions { CompressionQuality = 92 }); does not execute.no error , no nulls just that the debugger skips lines :(

Did I do the correct corrections?Do you have any idea why the takephotasync command is skipped?
(permissions were requested,camera opens when stepping in, but after that something is not working as it is supposed to work)

Thnx in advance,

@Kiran23-ui
Copy link

Thanks @savvaskef
Helped me in solving the issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants