Giter VIP home page Giter VIP logo

Comments (23)

agat366 avatar agat366 commented on July 29, 2024 6

I am experiencing this issue. And what's strange, it's happening only on Samsung (Android 9 and 10), any other Android device seems working fine.
CheckPermissionStatusAsync works well on the fist call, but then after calling RequestPermissionAsync (and allowing it), any further calls of any of those gets to eternal waiting for result.
Any thoughts?

from permissionsplugin.

conrad90909 avatar conrad90909 commented on July 29, 2024 4

@LasseNordqvist Looking at your code you have the same issue I had.

in OnRequestPermissionsResult in MainActivity replace:

Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

With

PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);

This solved the problem for me!

from permissionsplugin.

jamesmontemagno avatar jamesmontemagno commented on July 29, 2024

Did you add the Permissions to your manifest?

Also did you add the code into your main activity? Did you add a break point to make sure that it gets forwarded on.

from permissionsplugin.

remingtonsutton avatar remingtonsutton commented on July 29, 2024

from permissionsplugin.

jamesmontemagno avatar jamesmontemagno commented on July 29, 2024

Are you also compiling against Android 7.1? This is on the first page of the Android projects properties.

So, let's walk through this based on your code:

1.) Does it return from "CheckPermissionStatus"
2.) Does it Return from ShouldShowRequestPermissionRationale?
3.) Does it hit your breakpoint on await RequestPermissionsAsync
4.) Does it pop up a dialog box?
5.) In your MainActivity add a breakpoint on the overridden method does it hit this?

I am most interested in the 5th one to see what happens as this is waiting for the system...

from permissionsplugin.

jamesmontemagno avatar jamesmontemagno commented on July 29, 2024

Here is your exact same code and is working great:
App49.zip

See what is different between yours and mine

from permissionsplugin.

remingtonsutton avatar remingtonsutton commented on July 29, 2024

from permissionsplugin.

remingtonsutton avatar remingtonsutton commented on July 29, 2024

from permissionsplugin.

remingtonsutton avatar remingtonsutton commented on July 29, 2024

My code is AppCompat and uses Xamarin.Forms so it's not really like the example you gave much at all.

I think the issue is in point number 5 of not hitting the overridden method -- so on that, do you have any clue as to why it is ignoring that??

from permissionsplugin.

jamesmontemagno avatar jamesmontemagno commented on July 29, 2024

Based on the code you gave me it is not appcompat: https://user-images.githubusercontent.com/10901237/27601608-f39d679e-5b3d-11e7-9d51-f97a64823aef.png

Which is why I changed it. I use this exact code in appcompat and non-appcompat in about 10+ apps so I know it works and used by tons.

You could just change it to this:


    [Activity(Label = "App49", Icon = "@drawable/icon", Theme="@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
        }

        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
        {
            Plugin.Permissions.PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }

and it will also work just fine as I tested it.

I would highly recommend not using your Thread.Sleep as it is not needed at all as I showed in my example.

In summary though
You will have to send me a sample of it not working and I am sure there is something wrong in your setup of code.

from permissionsplugin.

remingtonsutton avatar remingtonsutton commented on July 29, 2024

OK, it looks like changing the Target version to 23, 24 or 25 made absolutely no difference. After the permissions issue I was able to get past the same geolocator issue by simply blasting the GetPositionAsync until something was returned. It looks like it takes about 120 attempts to get something, but I can't move forward without it, so it has to get done. I agree that these sort of loops aren't elegant, but no other solution has worked.

image

from permissionsplugin.

remingtonsutton avatar remingtonsutton commented on July 29, 2024

This was a very short lived success. It worked about 6 times before no longer working on emulator or physical device. When it did work, it would eventually crash the application -- despite my later attempts to track and abort the threads once a location was found.

image

from permissionsplugin.

jamesmontemagno avatar jamesmontemagno commented on July 29, 2024

I took a look at the source code example that you sent me and unfortunately I simply do not have the time to correct or comment on all of the issues going on.

I highly recommend looking at getting started with Async/Await Tasked based development: https://blog.xamarin.com/getting-started-with-async-await/

Here are a few tips:

  1. Don't use threads like that as you have things running all over the place and locking
  2. Calling .Result on a Task is going to lock your UI thread and application
  3. Don't initialize and call async logic in your app constructor... it hasn't even loaded yet and you are locking the app from starting

Take a look at the sample https://github.com/jamesmontemagno/GeolocatorPlugin/tree/master/samples as it has a sample of everything you could possibly want to do with the plugin including permissions.

from permissionsplugin.

remingtonsutton avatar remingtonsutton commented on July 29, 2024

from permissionsplugin.

remingtonsutton avatar remingtonsutton commented on July 29, 2024

As I mentioned, this solution isn't ideal and it's a total hack. But requesting the location continuously is the only way I ever get a response -- ever. I know well that this isn't a proper method. But there isn't much in terms of an explanation as to why GetPositionAsync() only returns a response every 20 requests and when it is called on new threads... no matter where it's called from.

from permissionsplugin.

ChaseFlorell avatar ChaseFlorell commented on July 29, 2024
public class App
{
    private GeoCoordinate _position;
    public App()
    {
        MainPage = GetMainPage();
    }
   bool isBusy;
    protected override async void OnStart()
    {
        // there's probably overhead to doing this in both OnStart and OnResume, but last time I checked OnResume also runs OnStart
        SetPositionAsync().ContinueWith(r => {});;
    }

    protected override async void OnResume()
    {
        // there's probably overhead to doing this in both OnStart and OnResume, but last time I checked OnResume also runs OnStart
        SetPositionAsync().ContinueWith(r => {});;
    }

    private async Task SetPositionAsync()
    {
        if(_position != null && !isBusy) 
            return;
        isBusy = true;
        try
        {
            _position = await _locator.GetPositionAsync(TimeSpan.FromSeconds(10));
        }
        catch(Exception ex)
        {

        }
       finally
      {
           isBusy = false
      }
    }
}

from permissionsplugin.

imhrushi avatar imhrushi commented on July 29, 2024

Is the problem solved? I am experiencing exact same problem.
In the 5 steps above, first 3 are working. However, ShouldShowRequestPermissionRationaleAsync returns true. Then I have a displayalert to show rationale, but it never shows up on screen. So I commented it out.
Then
4.) Does it pop up a dialog box?
yes RequestPermissionsAsync does pop up. When I hit deny or allow, the popup goes off, but the app hangs. The call never returns. But if I stop debugging and run again, I can see that the decision taken is saved properly. Like if I hit allow.
5.) In your MainActivity add a breakpoint on the overridden method does it hit this?
No it does not hit this breakpoint.

Any idea how to solve this? I am checking this in VS 2017 with android oreo 8.1 API 27

from permissionsplugin.

imhrushi avatar imhrushi commented on July 29, 2024

by the way, the Plugin.CurrentActivity nuget package is not installing on my project. It gives error as below.
Package Plugin.CurrentActivity 2.1.0.4 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package Plugin.CurrentActivity 2.1.0.4 supports: monoandroid44 (MonoAndroid,Version=v4.4)

Update:
I installed the Plugin.CurrentActivity package on ProjectName.android project and it installed properly.
Uninstalled and again installed the permissions package. But the problem of RequestPermissionsAsync remains same.
I did not have mainapplication.cs file created automatically nor I had it already in my solution.
I added this file and I started getting error of GenerateJavaStubs.
After searching, I found the solution to remove the ifdef statements from assemblyinfo.cs. Did so and now the project is compiling.

So now in all, it seems I have all the required things placed in my solution. However, the problem on this thread is still there.

2 issues still exists.

  1. displayalert to show rationale never shows up on screen. The app hangs after this call. So I commented it out.
  2. RequestPermissionsAsync does pop up the qn. When I hit deny or allow, the popup goes off, but the app hangs. The call never returns. But in settings I can see that the decision taken is saved properly. Like if I hit allow, the setting is changed.
    But what to do about app getting in hanged state?
    Please help.

Any confirmed solution for this issue?

from permissionsplugin.

wodaidai avatar wodaidai commented on July 29, 2024

Hi imhrushi

I had same issue that #5 is never called.
And found out it was due to the position of 'Plugin.CurrentActivity.CrossCurrentActivity.Current.Init' in OnCreate. I had it before base.OnCreate.

you can try to make sure:

    protected override void OnCreate(Bundle bundle)
    {
		FormsAppCompatActivity.ToolbarResource = Resource.Layout.Toolbar;
		FormsAppCompatActivity.TabLayoutResource = Resource.Layout.Tabbar;
		base.OnCreate(bundle);
		Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);   <--------- ** after OnCreate
		global::Xamarin.Forms.Forms.Init(this, bundle);
		LoadApplication(new App());
    }

    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
    {
        PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    }

from permissionsplugin.

LasseNordqvist avatar LasseNordqvist commented on July 29, 2024

Hi get the same result. Have tested a new project from Visual studio 2019, Empty xam app only android.
Add Xam.Plugin.Media. follow readme file. every thing works until

var results = await CrossPermissions.Current.RequestPermissionsAsync(Plugin.Permissions.Abstractions.Permission.Camera);
never returns to that…

Break point hits public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)

Test project is added below.

MissPer.zip

from permissionsplugin.

conrad90909 avatar conrad90909 commented on July 29, 2024

Also I don't think you want this commented out:

base.OnRequestPermissionsResult(requestCode, permissions, grantResults);

from permissionsplugin.

LasseNordqvist avatar LasseNordqvist commented on July 29, 2024

@LasseNordqvist Looking at your code you have the same issue I had.
in OnRequestPermissionsResult in MainActivity replace:
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
With
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
This solved the problem for me!

Perfect, This solved this problem. :)

from permissionsplugin.

rootflood avatar rootflood commented on July 29, 2024

ok i found the solution
we need this but this block UI thread

var status = Permissions.RequestAsync<Permissions.Camera>().GetAwaiter().GetResult();

we need other thread which can wait for result
so we change it to this and its work

var status = Permissions.RequestAsync<Permissions.Camera>();
new System.Threading.Thread(() =>
 {
    status.GetAwaiter().GetResult();
 }).Start();

but i think it must fix because this is a logic bug

from permissionsplugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.