Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting Background Locator on Android 12 error (PlatformException('registerLocator' requires the ACCESS_FINE_LOCATION permission., null, null, null)) #339

Open
andrewzakhartchouk opened this issue Jun 17, 2022 · 1 comment

Comments

@andrewzakhartchouk
Copy link

I had not noticed this earlier in the year for whatever reason, but on background_locator 1.6.6, Android 12 devices would crash when trying to start the locator.
The error/crashes still persist when upgrading to the latest version (1.6.12).
Older versions of Android do not have this issue.

I/flutter ( 8473): Error :  PlatformException('registerLocator' requires the ACCESS_FINE_LOCATION permission., null, null, null)
I/flutter ( 8473): StackTrace :  #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
I/flutter ( 8473): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
I/flutter ( 8473): <asynchronous suspension>
I/flutter ( 8473): #2      BackgroundLocator.registerLocationUpdate (package:background_locator/background_locator.dart:45:5)
I/flutter ( 8473): <asynchronous suspension>
I/flutter ( 8473): #3      _MenuScreenState._startBackgroundLocator (package:myproject/views/menu_screen.dart:734:12)
I/flutter ( 8473): <asynchronous suspension>
I/flutter ( 8473): #4      _MenuScreenState._startGps (package:myproject/views/menu_screen.dart:515:5)
I/flutter ( 8473): <asynchronous suspension>
I/flutter ( 8473): ---------------------- WRITING TO PATH /storage/emulated/0/Android/data/myproject.android/files

With some poking around, the piece of code that throws this error (found in BackgroundLocatorPlugin.kt) can be commented out to stop causing the error. This is only a temporary fix, but perhaps can help whomever is better versed with this package.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
                    context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
                    == PackageManager.PERMISSION_DENIED) {

                val msg = "'registerLocator' requires the ACCESS_FINE_LOCATION permission."
                result?.error(msg, null, null)
                return
            }
@iamsahilsonawane
Copy link

@andrewzakhartchouk

Two things that can cause this issue:

  1. Android version should at least be API 23 (Marshmello) or Android 6.
  2. No permission for ACCESS_FINE_LOCATION added in manifest

IMO, most probably it's a permission issue.

To add the permission in the manifest:
Add <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> in your android manifest file.

Ex: Check out this file for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants