Handle "dont ask again " Location Permissions Xamarin Forms - android

I got this dilemma. I am using TK-TORBEN-Maps ,Xamarin Forms. I did implement all the runtime permissions . however, if an user clicks "dont ask me again" what can I do to stop the app from crashing.
I need to let them pass even if they didnt accept and the first page is the map. is there anyway I could still display the map with those permission being denied?

It seems that you could not use the map without the permission.
I think you could explain to your users why the app needs the permission. For example, you could use ShouldShowRequestPermissionRationale.
string permission = Manifest.Permission.AccessFineLocation;
if (ShouldShowRequestPermissionRationale(permission))
{
//Explain to the user why we need to read the contacts
Snackbar.Make(layout, "Location access is required for some reason ", Snackbar.LengthIndefinite)
.SetAction("OK", v => RequestPermissions(PermissionsLocation, RequestLocationId))
.Show();
return;
}
You could refer to this blog for more information.
If you want the app not crash, you could try to navigate to another page after user denies the request.

Related

React Native Permission rationale not showing

I'm having a trouble with react native permission rationale. It is not showing though I already put it in my code.
const rationale = { title: 'Permission', message: 'message' }
const res = await PermissionsAndroid.request(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION, rationale);
What is the problem why it's not showing? Thank you for your help.
Late reply, but perhaps this will help someone else who lands here in the future:
I struggled with this as well recently, until I dug into the documentation on PermissionsAndroid:
If rationale is provided, this function checks with the OS whether it is necessary to show a dialog explaining why the permission is needed (https://developer.android.com/training/permissions/requesting.html#explain) and then shows the system permission dialog.
While not immediately clear from that line alone, following the provided link to Google's Documentation yielded this valuable snippet:
If the ContextCompat.checkSelfPermission() method returns PERMISSION_DENIED, call shouldShowRequestPermissionRationale(). If this method returns true, show an educational UI to the user. In this UI, describe why the feature, which the user wants to enable, needs a particular permission.
Essentially, you won't see the rationale on the initial request; it will only be presented after the user has expressly denied the permission (either via the system dialog or through settings). Hope it helps!

How to ask multiple permissions in a react-native application?

Right now I am building an applications which uses multiple device features like location, camera, storage and contacts.
I want to know if there is any way that allows users to enter into my application if and only if all the permissions are granted.
I've tried using react-native-permissions and the code snippet is as follows
Permissions.request('photo').then(() => {
Permissions.request('location').then(() => {
Permissions.request('camera').then(() => {
Permissions.request('contacts').then(() => {
Permissions.request('notification').then(() => {
console.log('PERMISSIONS ASKED');
});
});
});
});
});
The above code works only at the first time and if the user clicks deny then it is not asking again. Can any one help me with this.
Thanks in advance
Yes, once a user denies a permission he won't be asked for the permission again(iOS). He have to go back to settings and manually update the permissions.
It is not a good practice to ask all the permissions at once, the right way to ask is to alert for the permission when user initiate the usage of services like (location, camera).
Any way if you would like to ask all the permissions at once then you can check if the permission is in denied state, if so you can show an alert to open settings and change the permission.
Permissions.check('location', { type: 'always' }).then(response => {
this.setState({ locationPermission: response })
})

Reasking Android/iOS permissions in case the user refused in the first place

I'm working on a Unity application right now. And we have Vuforia based AR stuff (so we need camera permission) as well as geolocated features (location permission needed here).
When I install my app, I get asked for those permissions, so that's ok. But what if I decline ? The app still launches and I can use it... As long the camera and location features are not needed...
How can I display the same permission dialog again to my user, ideally through C# code, whenever he clicks on a button that leads to one of these features ?
If this is not possible, what should I do ? Because right now, the only way to get those alerts being displayed again is to leave and launch the app again...
Thanks for any help on this !
Vinny
On iOS, you can't - once user declines, it's not possible for you to spam them with permissions dialog.
What you can do is explain the user that they need to grant the app certain permissions, and display a button taking them to application settings. You can open application's settings on your device like so (Swift)
guard let url = URL(string: "App-Prefs:") else { return }
UIApplication.shared.openURL(url)
or in C#
Application.OpenURL("App-Prefs:");

Marshmallow - Google Maps Runtime permission issue

I'm using the Google location API to show the users location on the map.
When the app loads for the first time, rationale dialog is displayed explaining why user needs to enable access to location. Then, runtime permission dialog is shown, and users clicks “Allow” to enable location access. The Map then loads fine without any crashes.
However, when the app resumes (after going into background), no rationale dialog appears since user has already granted location access. In this scenario, only the runtime permission dialog appears. Now if the user clicks “Deny”, the app crashes. This code works fine in Android versions below M (Lollipop, Jellybean, KitKat etc.)
Is there a way to handle the runtime exception at this stage?
The error is :
java.lang.SecurityException: Client must have ACCESS_FINE_LOCATION
permission to request PRIORITY_HIGH_ACCURACY locations.
I'm using the standard Sample MyLocation demo app without any 3rd party library:
GoogleMaps MapDemo on Github
I've also tried using the PermissionsDispatcher Library, but the same errors persist.
PermissionDispatcher Android-Google-Maps-Demo
private void enableMyLocation() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission to access the location is missing.
PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE,
Manifest.permission.ACCESS_FINE_LOCATION, true);
} else if (mMap != null) {
// Access to the location has been granted to the app.
mMap.setMyLocationEnabled(true);
}
}
Any help is highly appreciated.
Make sure about that you have add right permission in your Manifest files about what permission you are asking and needed exactly
And may be problem with your code.
Try this library: RuntimePermission Library
To ask permission manually.

Why is `hasEnrolledFingerprints` giving error that it requires a permission only in my Fragment but not in the Activity in Google's Example?

I am trying to implement the Google's Fingerprint API in my app (in my Fragment specifically). Google has given an example but it's implemented inside an Activity here.
My specific question is that the code below to check if there are enrolled fingerprints already, it is giving me an error (screenshot below):
Question --> What change do I need to do to make it work in my Fragment (as opposed to an activity like Google has)?
if (!mFingerprintManager.hasEnrolledFingerprints()) {
purchaseButton.setEnabled(false);
// This happens when no fingerprints are registered.
Toast.makeText(getActivity(),
"Go to 'Settings -> Security -> Fingerprint' and register at least one fingerprint",
Toast.LENGTH_LONG).show();
return;
}
Android 6.0 must 'ask' for permission at run time. https://developer.android.com/training/permissions/requesting.html
Dangerous permissions can give the app access to the user's
confidential data. If your app lists a normal permission in its
manifest, the system grants the permission automatically. If you list
a dangerous permission, the user has to explicitly give approval to
your app.
Even if you have <uses-permission android:name="android.permission.USE_FINGERPRINT"/> in your manifest, My understanding is that you must ask for the permission. So it looks like the error is because your app doesn't have -run time- permission to use the fingerprint manager.
(only like 90% sure of this, since I'm sticking with 5.0 for now, sorry)
Update: http://developer.android.com/reference/android/Manifest.permission.html#USE_FINGERPRINT
public static final String USE_FINGERPRINT ---------- Added in API level 23
Allows an app to use fingerprint hardware.
Protection level: normal
So it appears you shouldn't need this permission at run time.
1) Do you have the permission in your manifest?
2) You should put the following code in yours to check to see if permission is revoked/not given for some reason.
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.USE_FINGERPRINT) // this might need massaged to 'android.permission.USE_FINGERPRINT'
!= PackageManager.PERMISSION_GRANTED) {
Log.d ("TEST", "You don't have permission");
}
(or something close to this) like the example from https://developer.android.com/training/permissions/requesting.html

Categories

Resources