Comments (23)
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.
@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.
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.
from permissionsplugin.
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.
Here is your exact same code and is working great:
App49.zip
See what is different between yours and mine
from permissionsplugin.
from permissionsplugin.
from permissionsplugin.
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.
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.
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.
from permissionsplugin.
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.
from permissionsplugin.
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:
- Don't use threads like that as you have things running all over the place and locking
- Calling .Result on a Task is going to lock your UI thread and application
- 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.
from permissionsplugin.
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.
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.
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.
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.
- displayalert to show rationale never shows up on screen. The app hangs after this call. So I commented it out.
- 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.
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.
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.
from permissionsplugin.
Also I don't think you want this commented out:
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
from permissionsplugin.
@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.
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)
- RequestPermissionsAsync returns Denied directly if users denied the first time HOT 2
- Update samples to Generics HOT 1
- RequestPermissionsAsync hanging possibly with XPC Connection Error HOT 3
- Updated Plugin.Permissions implementation for current versions of android. HOT 1
- Bug : Camera and Microphone permissions are unknown. HOT 1
- Xamarin Forms project, Droid, app not asking for permissions HOT 1
- RequestPermission always returns Granted
- Android ACCESS_MEDIA_LOCATION Permission not handled by the plugin HOT 5
- Permission plugin version 6.0.1 crashes the app HOT 2
- Scoped storage permission on Xamarin Android 10+? HOT 3
- Error XA2006 TargetFrameworkVersion Android 10 HOT 1
- RequestPermissionAsync<LocationPermission>() hangs with Xcode 12/iOS 14 HOT 4
- [BUG] RequestPermissionAsync<>() in XCode12/IOS14 not returning any value. HOT 6
- Accessing Censor text to replace with -- instead of ** HOT 1
- RequestPermissionAsync on Application Load throws null ref HOT 4
- RequestPermissionAsync HOT 1
- await CrossPermissions.Current.RequestPermissionAsync<LocationPermission>() HOT 2
- Android ACCESS_MEDIA_LOCATION Permission not handled by Xamarin.Essentials HOT 1
- how Request accessibility Permission and Floating window Permission ?
- Path to Maui? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from permissionsplugin.