Request permissions do not continue execution on Android

MaxenceSAUNIERMaxenceSAUNIER USMember ✭✭✭
edited October 2018 in Xamarin.Forms

Hello,

When I request the permissions on Android, the permission windows appear and once they are accepted, the code stops are execution. The application does not crash, there is no except, just a freeze of code execution.
Can you help me ?

try{

    PermissionStatus camera_status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
    PermissionStatus storage_status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);
    PermissionStatus location_status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

    if (camera_status != PermissionStatus.Granted || storage_status != PermissionStatus.Granted || location_status != PermissionStatus.Granted)
    {
        Dictionary<Permission, PermissionStatus> results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera,* Permission.Storage, Permission.Location });
        camera_status = results[Permission.Camera];
        storage_status = results[Permission.Storage];
        location_status = results[Permission.Location];
    }

    if (camera_status != PermissionStatus.Granted || storage_status != PermissionStatus.Granted || location_status != PermissionStatus.Granted)
    {
        await Application.Current.MainPage.DisplayAlert("ERREUR", "Vous devez autoriser l'application à accéder à votre appareil photo et votre localisation !", "ok");
        if (Device.RuntimePlatform == Device.iOS)
            CrossPermissions.Current.OpenAppSettings();
    }
}catch(Exception e)
{
    string resulttest = e.Message;
}

Thanks,

Best Answers

  • MaxenceSAUNIERMaxenceSAUNIER US ✭✭✭
    Accepted Answer

    I have an error on the : OnRequestPermissionsResult.
    I modified it to match the GitHUB documentation and it works again. Thank you.

Answers

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭

    Which API level is this?

  • MaxenceSAUNIERMaxenceSAUNIER USMember ✭✭✭
    edited October 2018

    Hello James and thanks for your intervention.

    On the Manifest
    Minimum API Level : 15
    Target API Level : 28

    My phone API Level : 26

    It's a Huawei Psmart.

    Thanks for your help.

  • MaxenceSAUNIERMaxenceSAUNIER USMember ✭✭✭

    up

  • MaxenceSAUNIERMaxenceSAUNIER USMember ✭✭✭

    Up

  • MaxenceSAUNIERMaxenceSAUNIER USMember ✭✭✭

    up

  • MaxenceSAUNIERMaxenceSAUNIER USMember ✭✭✭
    edited October 2018

    up. I need help. And not have response after 8 days. Please. Thanks.

  • MaxenceSAUNIERMaxenceSAUNIER USMember ✭✭✭
    Accepted Answer

    I have an error on the : OnRequestPermissionsResult.
    I modified it to match the GitHUB documentation and it works again. Thank you.

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭

    How did you find the error? Was it using logcat? What error did you get, and how did you resolve it?

  • MaxenceSAUNIERMaxenceSAUNIER USMember ✭✭✭
    edited October 2018

    With the log monitor I have find this line in error : 10-31 10:37:17.881: E/WindowManager(1260): win=Window{9e797d9 u0 com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity EXITING} destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true

    So, I have search on internet and people were saying the problem is on Android activity. I have check MainActivity and I have change autocompletion problem :
    Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    to
    PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭

    Thanks - that's really useful to know!

  • MaxenceSAUNIERMaxenceSAUNIER USMember ✭✭✭

    Thanks to you

Sign In or Register to comment.