Comments (17)
for every one that will read this, use:
beaconManager.setBackgroundScanPeriod(1000l);
beaconManager.setBackgroundBetweenScanPeriod(5000l);
beaconManager.updateScanPeriods();
that will scan for one second every 5 seconds.
from android-beacon-library.
The device will enter deep sleep when the user switches off the screen and no other processes are keeping it awake (WAKE_LOCK) and the device is not connected to a power source.
In this case postDelayed is not waking up because the cpu is sleeping.
More detailed information here: http://binarybuffer.com/2012/07/executing-scheduled-periodic-tasks-in-android
from android-beacon-library.
Interesting point. I am not aware of this issue. Can you clarify what you mean by "enters deep sleep"?
from android-beacon-library.
Have you actually witnessed this behavior? I often run apps based on the library after switching off the screen with the device not connected to a power source, and scans still appear to happen as expected. Based on the link above I agree that this should be a problem, but it is not consistent with my experience.
from android-beacon-library.
Yes i see this behaviour on my device. I just tested it on a Galaxy Nexus with 4.3, it stops scanning entirely.
Maybe some other app is keeping your device awake? I have no experience with this tool, but it might work: https://play.google.com/store/apps/details?id=com.uzumapps.wakelockdetector
from android-beacon-library.
I'm pretty sure I'm seeing this, too. Tried doing some battery life tests last night with this setup and it doesn't seem to have scanned at all.
- Nexus 5, L preview
- Stock Google apps only + my test app
- Airplane mode with Bluetooth on (i.e. Wifi off, Cell radio off)
- Sync turned off for all Google apps (Settings > Accounts > Google > [email protected] > Unselect each app [so it won't sync/wake up the system])
- Not plugged into usb
I'm using master at 69540cd.
from android-beacon-library.
Is this just an issue with Android L? My understanding is that bluetooth scanning stops deep sleep on 4.4 and earlier. For Android L, the solution is probably to switch to their new APIs for low power BLE scanning rather than programmatically cycling scanning on and off.
from android-beacon-library.
Researching this more, it seems like the real issue is that if a device enters deep sleep there is nothing else going on to wake it up, the scans may stop. As soon as something else wakes up the device, scans should restart within a second, because the maximum handler time is one second. This seems like at most an edge case that does not affect most users.
One way to fix this is to set up a secondary AlarmManager that wakes up the library after the betweenScanPeriod expires. This would cause the library on default settings to always force an exit from deep sleep every five minutes. Is this really a reasonable approach? On Android L, this may not be necessary, as hardware bluetooth LE scanning will always be active and will presumably wake up the device from deep sleep if a new device is discovered.
from android-beacon-library.
I think background-scanning is only really useful like it is implemented on iOS and (maybe) Android L. The device needs to detect the beacon almost immediately, otherwise the user will already be somewhere else. If you want to detect that the user entered some area a delay of 5 minutes is not really useful.
Scanning in the foreground when the app is active is working ok, but i think background-scanning on Android before L is not really going to work. You don't want to drain the battery but detection should be much faster than 5 minutes.
Just my 2 cents :)
from android-beacon-library.
I have implemented an AlarmManager implementation to wake scanning back up if the phone goes into deep sleep. Code is here:
https://github.com/AltBeacon/android-beacon-library/tree/alarm-manager
Does anybody know a good way to test this? How to I force my phone into deep sleep for testing?
from android-beacon-library.
It should enter deep sleep automatically when it is not connected to USB and no app is keeping a WAKE_LOCK.
There are apps in the playstore that can show you if you have any apps that are keeping the device awake.
from android-beacon-library.
This has been put into the 2.1 release here: This is now available in 2.1 here:
https://github.com/AltBeacon/android-beacon-library/releases/tag/2.1-beta1
Any feedback on how it works would be appreciated.
from android-beacon-library.
@davidgyoung Could you please elaborate a bit how this is supposed to work?
When the AlarmManager wakes up the device it only will execute onReceive method of StartupBroadcastReceiver before going to deep sleep again.
From testing on 4.4.2 I can say that it in fact doesn't work with this approach.
from android-beacon-library.
@eyeled, when the StartupBroadcastReceiver
is triggered, if the app was not running prior, it triggers the regular app startup lifecycle. That means that if your app has a custom Application
class, its onCreate
method will be fired, which is the recommended place for initializing the library's RegionBootstrap
class. If this is done, this will start scanning.
from android-beacon-library.
@davidgyoung The case I'm talking about is when the app already is running in background (mBackgroundFlag is set to true) and the device wakes up from deep sleep due to the AlarmManager callback registered in CycledLeScanner.setWakeUpAlarm().
This is what the original issue is all about and the current implementation doesn't seem to have fixed the original bug.
from android-beacon-library.
The library uses a combination of a Handler and and Alarm. The Handler is the normal way of cycling scanning. The Alarm is just used as a backup. In deep sleep, the Handler firing will be delayed and will not fire while the app is in deep sleep. When the Alarm goes off in deep sleep, it releases the hold on the Handler and it will fire shortly after the Alarm brings the app from deep sleep.
from android-beacon-library.
What makes you assume that the operating system will execute anything other than the onReceive method when an alarm goes off?
Quote from the AlarmManager docs: "The Alarm Manager holds a CPU wake lock as long as the alarm receiver's onReceive() method is executing. This guarantees that the phone will not sleep until you have finished handling the broadcast. Once onReceive() returns, the Alarm Manager releases this wake lock. This means that the phone will in some cases sleep as soon as your onReceive() method completes."
From my logs I can only say that it doesn't work.
And even if it worked then the scanning interval in background would effectively go down to every 5 minutes which is not very useful. Cf. #179
from android-beacon-library.
Related Issues (20)
- Range beacons when app is terminating HOT 7
- Beacons ranging not working on android 13 HOT 1
- App stops scanning right after screen is locked and starts giving the results right after unlocked HOT 1
- Android beacon library - multiple regions monitoring - unable remove regions HOT 2
- startForeground Exception when app is not in foreground HOT 3
- StartupBroadcastReceiver throws NullPointerException HOT 2
- No beacons after locked screen HOT 19
- Cannot parse iBeacons HOT 3
- BeaconService.startForegroundIfConfigured HOT 12
- TargetSdk 34 (android 14) Beacon foreground service no longer working due to new Google restriction HOT 1
- Do we have sample app to implement the library including the operation running in Background HOT 4
- Only a maximum of 2 beacons can be received at a time HOT 1
- java.io.FileNotFoundException android-distance.json HOT 2
- android-distance.json database not found
- Crash when parsing _lengthy_ beacon data fields HOT 3
- Custom Distance calculator is being overwritten HOT 6
- Samsung devices not detecting beacons by intent after first screen off
- Can we use this with tauri mobile? HOT 3
- Main thread can be blocked sometimes
- Android 14 didDetermineStateForRegion no beacon is detected or scanned
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-beacon-library.