Git Product home page Git Product logo

Comments (7)

sestegra avatar sestegra commented on August 20, 2024

I will try to update the code to use the Context directly available from registrar to avoid to pass by the Activity.

from flutter-geolocator.

mvanbeusekom avatar mvanbeusekom commented on August 20, 2024

@sestegra I checked our code and the error happens on the spot where the native code returns the result to Dart using the instance of the MethodResult class. Looking into the "android_alarm_manager", it looks like the printHello method is called from the background. Did you follow the instructions on the documentation of the "android_alarm_manager" explaining the usage of other Flutter plug-ins together with the "android_alarm_manager" (to following is copied directly from the README):

If alarm callbacks will need access to other Flutter plugins, including the alarm manager plugin itself, it is necessary to teach the background service how to initialize plugins. This is done by giving the AlarmService a callback to call in the application's onCreate method. See the example's Application overrides. In particular, its Application class is as follows:

public class Application extends FlutterApplication implements PluginRegistrantCallback {
  @Override
  public void onCreate() {
    super.onCreate();
    AlarmService.setPluginRegistrant(this);
  }

  @Override
  public void registerWith(PluginRegistry registry) {
    GeneratedPluginRegistrant.registerWith(registry);
  }
}

from flutter-geolocator.

sestegra avatar sestegra commented on August 20, 2024

@mvanbeusekom I not only follow the documentation, I updated the example (that implements the Application class) to call Geolocator.

Basically, I cloned the plugins project, update the example code with above snippet and run it.

from flutter-geolocator.

sestegra avatar sestegra commented on August 20, 2024

I still got the following error coming from permissions.

D/permissions_handler( 9153): Unable to detect current Activity.

from flutter-geolocator.

sestegra avatar sestegra commented on August 20, 2024

It works if I get permission from MainActivity.

from flutter-geolocator.

mvanbeusekom avatar mvanbeusekom commented on August 20, 2024

@sestegra the problem with the permissions can also be solved by taking care of them manually when the App starts using the permission_handler plugin.

Unfortunately to take care of permissions we do need an Activity (which makes sense because we need to show the user a dialog). So by taking care of the permissions manually when we are sure the App is running (before we launch services in the background) we can be sure there is an activity.

Then when the Geolocator gets called it will notice that all permissions are taken care of and will simply continue acquiring the location and not try to get the required permissions.

from flutter-geolocator.

mvanbeusekom avatar mvanbeusekom commented on August 20, 2024

@sestegra a quick follow up, we just release version 1.6.3 of the Geolocator plug-in which includes your changes. Thanks again for reporting the issue.

from flutter-geolocator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.