Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Android “gps requires ACCESS_FINE_LOCATION” error
Forum Updated to NodeBB v4.3 + New Features

Android “gps requires ACCESS_FINE_LOCATION” error

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 2 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Orby
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Thanks for sharing your findings. You should also bring that to the Qt Android development mailing list. You'll find there Qt's Android port developers/maintainers. This forum is more user oriented.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • O Offline
        O Offline
        Orby
        wrote on last edited by
        #3

        Thanks for the tip, I'll do that. I'm interested to get in touch with those guys anyway to extend the default implementation of the QML Map library.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          Extend it Android wise or globally ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • O Offline
            O Offline
            Orby
            wrote on last edited by
            #5

            I guess I'll have to see once I get in there. Ideally it would be global.

            I'd like to get two finger rotation logic implemented. Also I'd like to change how the zoom works; instead of showing the user a gray square while zooming, I'd rather zoom the best fit tile.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved