Git Product home page Git Product logo

Comments (4)

rahul-kumawat-vts avatar rahul-kumawat-vts commented on July 19, 2024

My requirement is i have to detect the beacon in each state either App in background, App is removed from Background and App is running in foreground.

from android-beacon-library.

davidgyoung avatar davidgyoung commented on July 19, 2024

The library supports a number of different "Scan strategies" that can be used to optimize background detections depending on your use case. All of these scan strategies are shown in the Application class of the reference app you mention above (all but one are commented out, but the comments provide instructions on configuring the other scan strategies.)

See this table for the pros and cons of each scan strategy:

https://altbeacon.github.io/android-beacon-library/detection_times.html

For your purpose, you probably want to consider the Foreground Service scan strategy or the Intent scan strategy. They are designed to give you the best results for background detections within the limits allowed by the Android operating system. Neither are perfect, but one should get you as close as possible to your goal.

from android-beacon-library.

rahul-kumawat-vts avatar rahul-kumawat-vts commented on July 19, 2024

@davidgyoung Which function is used to stop library foreground service from our app?

In our app have a stop button with Notification for foreground service.

from android-beacon-library.

davidgyoung avatar davidgyoung commented on July 19, 2024

Thy this to stop a previously configured foreground service:

fun stopForegroundService(context: Context) {
        val beaconManager = BeaconManager.getInstanceForApplication(context)
        for (region in beaconManager.monitoredRegions) {
            beaconManager.stopMonitoring(region)
        }
        for (region in beaconManager.rangedRegions) {
            beaconManager.stopRangingBeacons(region)
        }
        BeaconManager.getInstanceForApplication(this).disableForegroundServiceScanning()
    }

The last line disables the foreground service configuration. If you want to restart the foreground service later, you can omit that line -- that way the next time you start ranging or monitoring it will start up again.

Be a advised that Android 13 and 14 only allow starting a foreground service when the app is in the foreground (or other specific situations like on BOOT_COMPLETED).

from android-beacon-library.

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.