Git Product home page Git Product logo

Comments (20)

khairu-aqsara avatar khairu-aqsara commented on July 18, 2024 4

i have same case and problem with you, but i follow step on https://github.com/rekab-app/background_locator/wiki/Use-other-plugins-in-callback and it's work, here is my Application.kt

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin;
import io.flutter.view.FlutterMain
import rekab.app.background_locator.LocatorService

class Application : FlutterApplication(), PluginRegistrantCallback {
    override fun onCreate() {
        super.onCreate()
        LocatorService.setPluginRegistrant(this)
        FlutterMain.startInitialization(this)
    }

    override fun registerWith(registry: PluginRegistry?) {
        if (!registry!!.hasPlugin("io.flutter.plugins.sharedpreferences")) {
            SharedPreferencesPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.sharedpreferences"))
        }
    }
}

and change the Manifestfile.

<application
        android:name=".Application"

you need add shared pref plugin,change

import io.flutter.plugins.pathprovider.PathProviderPlugin

to this

import io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin;

and change

if (!registry!!.hasPlugin("io.flutter.plugins.pathprovider")) {
    PathProviderPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.pathprovider"))
 }

to this

 if (!registry!!.hasPlugin("io.flutter.plugins.sharedpreferences")) {     
   SharedPreferencesPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.sharedpreferences"))
}

and in the static callback just use the shared pref plugin as usual

SharedPreferences prefs = await SharedPreferences.getInstance();
String somthing = prefs.getString('somthing');

from background_locator.

mehdok avatar mehdok commented on July 18, 2024 4

@wemersonrv I think I can do that this weekend.

from background_locator.

RomanJos avatar RomanJos commented on July 18, 2024 1

Thats strange it work on some devices but not even on the emulator, have you tried to run the example ? Starting at boot mean that we need a way to start the plugin directly from kotlin and not dart and I think it would require a lot of changes idk

And i do the same lol

from background_locator.

RomanJos avatar RomanJos commented on July 18, 2024

Can you show LocationService.kt ? Look like you didn't do the step 3 of Android. At the moment we can't use plugins on IOS by the way

from background_locator.

vimalmistry avatar vimalmistry commented on July 18, 2024

@RomanJos I followed all 3 steps.
I created Application.kt and configured in manifest.xml.
I am not familiar with native programming.
Why IOS is not working? there is steps for configure in IOS.

from background_locator.

mehdok avatar mehdok commented on July 18, 2024

@vimalmistry The Document and the code need to be updated, I will do it this weekend. Please be hold until then.

from background_locator.

vimalmistry avatar vimalmistry commented on July 18, 2024

@mehdok ohh :( Did you updated doc? I found some new informations in readme.md
One question. What is requirement of minimum android version? My client complaints it is not working on their older devices!

from background_locator.

mehdok avatar mehdok commented on July 18, 2024

Minimum android sdk is 16.

from background_locator.

RomanJos avatar RomanJos commented on July 18, 2024

Actually I modified the README 3 days ago so make sure to match changes on your project, it may resolve your issues 😉
I'm using it on a real Android 4.4.2 (API 19) and it work well I only have issue setting the accuracy to HIGH so I left it to NAVIGATION

from background_locator.

mehdok avatar mehdok commented on July 18, 2024

@RomanJos Sorry your changes in document isn't merged yet. If there is something that can help @vimalmistry please copy paste it here.

from background_locator.

RomanJos avatar RomanJos commented on July 18, 2024

No I mean the one that are already merged

I created Application.kt and configured in manifest.xml.

Its LocationService.kt on the readme

from background_locator.

vimalmistry avatar vimalmistry commented on July 18, 2024

Thanks for replies. I actually configured using old doc (Application.kt). It works very well in most devices Except some devices and also I can not run it on emulator. But in physical device it works. But I found service is terminated after reboot. Is there any quick fix to auto start on reboot.
I am not a native developer. So I don't know much about .kt and .java file. I am just copy pasting every time.😇

from background_locator.

mehdok avatar mehdok commented on July 18, 2024

@vimalmistry I'm not sure why you can not get it working on some device or simulator, But I can confirm that the plugin is working fine on simulator, both Android and iOS.

On Android I can add the RECEIVE_BOOT_COMPLETED, it's not that hard to restart service when device rebooting, But it is something that only Android supports, as I know there is no similar feature on iOS, so for keeping everything equal I won't do it.

from background_locator.

TahaMalas avatar TahaMalas commented on July 18, 2024

Thanks for replies. I actually configured using old doc (Application.kt). It works very well in most devices Except some devices and also I can not run it on emulator. But in physical device it works. But I found service is terminated after reboot. Is there any quick fix to auto start on reboot.
I am not a native developer. So I don't know much about .kt and .java file. I am just copy pasting every time.😇

Hey, can you tell me how you managed to solve the issue? I'm getting the same problem with SharedPreferences package, while I'm trying to use it on the static callback function

from background_locator.

gpibarra avatar gpibarra commented on July 18, 2024

Have you followed the steps in the documentation?

https://github.com/rekab-app/background_locator/wiki/Use-other-plugins-in-callback

from background_locator.

wemersonrv avatar wemersonrv commented on July 18, 2024

@vimalmistry I'm not sure why you can not get it working on some device or simulator, But I can confirm that the plugin is working fine on simulator, both Android and iOS.

On Android I can add the RECEIVE_BOOT_COMPLETED, it's not that hard to restart service when device rebooting, But it is something that only Android supports, as I know there is no similar feature on iOS, so for keeping everything equal I won't do it.

@mehdok Any chance to convince you to make this implementation for Android?

Almost 90% here in Brazil are android devices: https://gs.statcounter.com/os-market-share/mobile/brazil

And worldwide is not so different: https://gs.statcounter.com/os-market-share/mobile/worldwide

from background_locator.

MazEbeid avatar MazEbeid commented on July 18, 2024

Below is the Java equivalent to the above if your project doesn't support Kotlin

<YOUR PACKAGE NAME HERE>
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import rekab.app.background_locator.LocatorService;
import io.flutter.plugins.firebase.cloudfunctions.CloudFunctionsPlugin;
import io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin;

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

                final String sharedPrefKey = "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin";
                final String functionsKey = "io.flutter.plugins.firebase.cloudfunctions.CloudFunctionsPlugin";
                if(!alreadyRegisteredWith(registry,sharedPrefKey))
                {
                   SharedPreferencesPlugin.registerWith(registry.registrarFor("io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"));
                }
                if(!alreadyRegisteredWith(registry,functionsKey))
                {
                        CloudFunctionsPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebase.cloudfunctions.CloudFunctionsPlugin"));
                }
        }
        private static boolean alreadyRegisteredWith(PluginRegistry registry, String key) {
                if (registry.hasPlugin(key)) {
                        return true;
                }else{
                        return false;
                }

        }

}

from background_locator.

ozz-rjq avatar ozz-rjq commented on July 18, 2024

@MazEbeid thanks! can you help with ios configuration?

from background_locator.

MazEbeid avatar MazEbeid commented on July 18, 2024

from background_locator.

mehdok avatar mehdok commented on July 18, 2024

@MazEbeid @ozz-rjq There is a bug with iOS that prevent the app to get a gps fix while app is terminated in iOS (or at least get a fix every 500 meter or so). Also there is a PR #59 which address this issue, but there is a bug with that too. It would be appreciated if anyone can help with that.

from background_locator.

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.