[Android-development] “gps requires ACCESS_FINE_LOCATION” error and workaround on Android API 23+
maitai
maitai at virtual-winds.org
Sat Feb 13 07:35:10 CET 2016
That seems important indeed, thanks for sharing
Any plan on qt side for that?
Philippe Lelong
Le 12-02-2016 23:32, Luke Dupin a écrit :
> As of Android API 23, there is a new way to request location permissions. It doesn't look like QT5.6 beta has been updated to use this method, so I wrote a quick work around. This API 23 change might affect the camera and contacts permissions also, I'm not sure.
>
> Before anyone says, I already have the fine location permission in my manifest:
> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
>
> Inside your android project, create a template. In the manifest, change:
> android:name="org.qtproject.qt5.android.bindings.QtActivity"
> to:
> android:name="com.my_company.my_project.MyActivity"
>
> Create the path inside your android template directory:
> src/com/my_company/my_project
>
> Now create the extended activity which requests the permissions as follows:
>
> public class MyActivity
> extends QtActivity
> {
> private static final String[] LOCATION_PERMS={
> Manifest.permission.ACCESS_FINE_LOCATION
> };
>
> private static final int LOCATION_REQUEST = 1337;
>
> @Override
> public void onCreate(Bundle savedInstanceState)
> {
> super.onCreate(savedInstanceState);
>
> //Ensure we can run the app
> if ( !canAccessLocation() )
> requestPermissions( LOCATION_PERMS, LOCATION_REQUEST );
> }
>
> @Override
> public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
> {
> //Figure out what was given to us
> switch(requestCode)
> {
> case LOCATION_REQUEST:
> if ( canAccessLocation() )
> log("Access to location is granted");
> else
> log("Access to location is denied");
> break;
> }
> }
>
> private boolean hasPermission(String perm)
> {
> return ( PackageManager.PERMISSION_GRANTED == checkSelfPermission(perm) );
> }
>
> public boolean canAccessLocation()
> {
> return hasPermission(Manifest.permission.ACCESS_FINE_LOCATION);
> }
>
> public static void log( String s )
> {
> Log.d("Radius", s );
> }
> }
>
> This "fix" was taken from the following post:
> http://stackoverflow.com/questions/32083913/android-gps-requires-access-fine-location-error-even-though-my-manifest-file [2]
>
> _______________________________________________
> Android-development mailing list
> Android-development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/android-development [1]
Links:
------
[1] http://lists.qt-project.org/mailman/listinfo/android-development
[2]
http://stackoverflow.com/questions/32083913/android-gps-requires-access-fine-location-error-even-though-my-manifest-file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/android-development/attachments/20160213/76c56386/attachment.html>
More information about the Android-development
mailing list