I have just started working on a android project and is using the Google Map API.
I am able to fetch the map on my app but when i try to enable the current location with map.setMyLocationEnabled(true);, the app says unfortunately app has stopped working.
When I removed the line map.setMyLocationEnabled(true); then it worked fine. Can anyone please help me to get the current location button enabled.
If you are using android 6.0 or above, you should:
Make sure you added ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION in your AndroidManifest file.
You need to check permission at run-time in this link: Requesting Permission
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app's functionality;
If you want an easy-to-use library for permission checking, I suggest Permission Dispatcher.
According to this, you need to have requested permission for either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION.
My guess is you haven't and your app is throwing a SecurityException.
Related
I have currently some troubles to make my app comply with the new "Google Background Location Policy".
Here is my situation :
My application is targeting Android Api 22 and Up
I have the following permissions required in my app : ACCESS_FINE_LOCATION
I need this permission to display the User position in a Map while the app is in Foreground and for Bluetooth Low Energy usage
I do not fetch location while the app is in Background
I don't understand how to setup the Google Play Console.
The only cases I can see are the following :
My application use location and is available starting from API 29, but do not require the ACCESS_BACKGROUND_LOCATION permission.
My application don't use Location and don't have any *_LOCATION permissions.
I am missing the case where :
My Application is available starting from API 22, So I don't have the ACCESS_BACKGROUND_LOCATION permission. But my app requires location permission in foreground and uses Bluetooth, so I need the ACCESS_FINE_LOCATION permission. I never request location in the background.
I guess the application already comply with the "Background Location Policy" since the app only fetch the location in foreground.
However my apps updates are always rejected due to this policy, so I am a little bit confused.
Why my app do not comply ?
Is it only because I have the permission ACCESS_FINE_LOCATION present in my app, and by default Google assume that the app request location in background ?
Do I need to restrict my app to Android 9 and older, in order to not get stuck with the automatic attribution of ACCESS_BACKGROUND_LOCATION permission?
Do I need to fill the Background Location Permission form in the Google Console and explain that I do not access location in the background ?
Something else ?
Thanks for your feedback on it.
try submitting and say you dont use background (declare foreground usage)
Probably you're requesting location update on a Service (even a foreground service)
This is kind of automatic scan from google.
Your app is targeting below API 29, uses ACCESS_FINE_LOCATION permission
is same with targeting API 29 and above and uses ACCESS_BACKGROUND_LOCATION
In my case, Google needed a video showing that the prominent disclosure was being displayed before requesting the runtime permission. The video needs to be uploaded to, say, YouTube and included in the Google Play console under App content->Permission declarations form->Video instructions. You also need to explain what triggers the request for background location permission.
I have an app which contains <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
Is there a way to delay asking the user for the location permission until they take an account which requires it? I've tried removing uses-permission from the XML, this breaks location even after programmatically asking for location permissions.
I do programmatically ask for location info, but that only seems to work if the permission is also specified in the XML.
I am assuming that you are experiencing this as you're targeting below Android 6.0?
As per the docs
Android 6.0 Marshmallow introduced a new permissions model that lets
apps request permissions from the user at runtime, rather than prior
to installation. Apps that support the new model request permissions
when the app actually requires the services or data protected by the
services.
Therefore, you will be unable to avoid requesting permissions before the user actually needs to use that particular service, unless you target a higher API level.
If you need permission, you can not remove it from manifest. If your target API is above 23 (Android 6) Just ask for permission programmatically when you need it. You as developer determine when to ask for permissions.
Otherwise if user's device is below android 6 or if your target API is below 23 then permissions will be requested at install time and you can not change it.
I want to ask for any permission to the user after installing the app.
Is it possible to request runtime permissions from current API(7.0) to API level 19 (4.4)?
I've read the documentation and I've tried a lot of examples.
Everything seems too complex and I've even seen plugins to request permissions.
The documentation provides an example usign several NuGet Packages:
https://developer.xamarin.com/samples/monodroid/android-m/RuntimePermissions/
But it only works with Android M (6.0 API level 23) and above...
This article talks about it:
https://blog.xamarin.com/requesting-runtime-permissions-in-android-marshmallow/
For example, in my case I want to check if the app have the "permission CAMERA" and if not ask for the user, something like this:
if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this, Manifest.Permission.Camera) != (int)Permission.Granted) {
// Permission has never been accepted
// So, I ask the user for permission
ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.Camera }, REQUEST_CAMERA);
} else {
// Permission has already been accepted previously
}
The application opens without displaying anything.
The check works but "RequestPermissions" don't ask anything to the user.
Why not show anything?
Why I need to use "ActivityCompat" if also doesn't work in versions prior to M?
Can anyone give me an example to request runtime permission from a simple code (compatible with versions prior to M)?
I got the same result as you, so did a little investigation. The trick is that you have to set permissions in 2 places.
1. In manifest
2. Request permissions in run time
As shown here https://developer.android.com/training/permissions/requesting.html
the result is different.
On all versions of Android, your app needs to declare both the normal and the dangerous permissions it needs in its app manifest, as described in Declaring Permissions. However, the effect of that declaration is different depending on the system version and your app's target SDK level:
If the device is running Android 5.1 or lower, or your app's target SDK is 22 or lower: If you list a dangerous permission in your manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.
If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.
Runtime Permissions were introduced in Android 6.0 (API 23 - Marshmallow). As such you will not be able to programmatically set up Runtime Permissions on any Android API lower than 23. The Requesting Runtime Permissions in Android Marshmallow guide you linked in your question is likely the best resource here, and the Check the SDK Version section shows the logic for checking the API level and preventing the Runtime Permissions workflows from being called on API levels prior to 23.
For previous API levels from 22 and prior you will need to add your install-time permissions in your AndroidManifest.xml as described in the Add Permissions to Android Manifest guide.
Besides setting your Permissions in Manifest.xml you can check the permission using Xamarin.Essentials: Permissions
It automatically prompt the user to Allow or Disallow the requested permissions.
A small question: I am trying to debug my App, developing in Android Studio, with my Smartphone. I have listed several uses-permission in my manifest. But when I debug the app, the smartphone does not ask me for the permission to use the permissions... will I nevertheless have access to my "uses-permission" permissions? If not, how can I debug it :D
Runtime permissions are a new thing on Android. They only work if your both Target API and the device you are using are level 23 or higher. If any of those is lower, then Runtime permissions do not work and old permission model is used. In old model, permissions are granted at install time and when you install your app via USB, you automatically accept all permissions. Still, in new permission model, you need to write code in async style, meaning that first you have to ask user for permission and supply a callback, in which you will know whether the user granted or denied specific permission. You can read more about that at officials docs.
I check if user has permission, but just wanna do that when he deny on Android Options. When he install my app, how can I set all permissions on. I saw that happens on Google I/O 2015 app.(You can turn off permission, but when you install, this permissions are already on).
Thanks!
The 2015 Google IO app targets API version 22, which means that it will not use the runtime permissions model, even if running on a device running Android 6.0 (API 23) and up. In this case, permissions are still granted at install time, but users can still go in and manually disable permissions.
If you are targeting API 23+, you must use the new runtime permissions model. No permissions will be granted to your application at install time.
I hope you speak Spanish, otherwise, use a translate tool. Android 6.0 changed the way permission works, dangerous permissions are disabled by default even if you define them in the manifest.
Check my post here, http://androidenespannol.blogspot.com/2015/11/solicitar-permisos-en-tiempo-de.html
Best regards