I have 2 apps that require background location. One is for Golfing, and one is for Sailing. In sailing you probably dont have the phone connected. In Golf it continuously connects and disconnects.
So what I found out is that the Wear OS simulator behaves differently from the Galaxy watch 4. On the simulator I get an update each 3 seconds. Now on the Galaxy watch 4 I get an update each 3 minutes when location is turned off on the Phone. When the location is turned on on the phone then I get an update each 3 seconds.
I have asked permissions for ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION. Ambient Mode Support is ON
In my preferred situation I receive an GPS update each second while the watch screen is on or off. Now I already tried several options to achieve this but it isn't working. I'm now at a point to think that the Galaxy Watch 4 with Wear OS just limits the GPS when the screen is off no matter what. Though, there are many workout apps that need background GPS for distance speed calculations so I can't imagine it isn't simply possible.
In a ViewModel I started fusedLocationProviderClient.requestLocationUpdates
I get an update each second when the screen is on. when the screen is off, no updates
Starting a Service
update each 3 seconds when screen is on. no updates when screen is off.
Starting a service with broadcastreceiver:
location update each 3 seconds when screen is on and update each 3 minutes when the screen is off.
Start a service with an ongoing notification and ongoing activity
Same results as 3
Service with ongoing activity and wakelocks
Same results as 3
I could share my code, but my primary question is. Is it possible to achieve my desired result and is it possible. A bonus would be a method to force use the WAtch GPS since it is essential in Golf as your phone is often 20 yards/meters away and the distance to the flag needs to be way more precise than that.
After a day of many trial and error i found the cause.
In my situation I had my Samsung Watch 4 and an Emulator in Android Studio. The galaxy watch was used in the Galaxy Wear app and the Emulator was paired in the Google Wear app. This causes a Conflict. I removed the Google Wear app from my phone and it started to work as expected.
Another thing I noticed is that when you run a service, it gets killed 30 seconds after the screen goes out. But, when your watch is on a Charger, that doesn't happen. As I often develop with the watch on the charges because the WIFI ADB debugging and GPS consume a lot of battery.
Related
I implemented getting location updates using FusedLocationProviderApi.
I need to track device location in background, when app is not running.
I followed the tutorials, I have a Service where I call requestLocationUpdates with an intent which starts a service.
I've purposely NOT implemented keeping a wake lock just to test and see that when the screen goes off, the device stops getting location updates. Once I verified that I could then go and implement the wake lock and expect the opposite, which is to see it working.
I used two devices: a Google Nexus 10 with KitKat and a Samsung Galaxy A5 (2016) with Lollipop.
On both devices, it keep sending updates (I'm sending the updates to a website).
I tested with screen off, after leaving device on a desk for a minute, and then walking again around the house.
I know Android 6 and Doze mode is more restrictive, but I want to nail and understand how it works on Android 4.4 and Android 5.
So frustrating! Any ideas how to actually make device go in sleep mode so I can see getting location updates stop working?
Funny, everything I've read is about making it work :)
EDIT: I'm confused why getting location updates is still working when screen is off even with an aggressive location update setup like the following:
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setFastestInterval(2);
locationRequest.setInterval(1000);
Thing about requesting location updates is that underneath it all, the LocationManagerService, which is what LocationManager uses, actually creates and acquires it's own wakelock. So technically, your device will never go to sleep as long as you have a location listener registered to actively receive GPS. Now, I know you are using Google's FusedLocationApi, but underneath it all, it does use LocationManager. If you are interested in understanding the location code a little better, here is the source code for LocationManagerService.
I'm testing a kiosk app that runs continuously. I have setup auto-updates in the Play Store and am trying to see when it updates. I left two tablets running for over 3 days, and only after they died and I restarted them did the updates occur. The app was not running on boot.
I tried to restart the devices during the 3 days to no avail and even the apps that weren't running didn't auto update so I know it's not because the app is running (my first assumption when doing research).
Looking online, I'm seeing a lot of people say that auto updates happen at random and only on wifi etc. I've had the tablet on wifi the entire time and let it charge over the first day to see if the power state changed anything.
Is there a way to test auto updating reliably? When does the Play Store do updates?
the last couple of days i was busy getting a service up and running for an phone gap application (using the eclipse ide with the device (motorola defy android 2.3.) connected to my computer)/ the service runs in the background when the application is off and has a timer scheduled that passes an intent to launch my application at irregular times/ everything is working as intended/ when the application is off and the device sleeps (screen is black) the timer is still running and at the scheduled time the device gets woken up, the lock removed and the app starts/ however, the bummer came when i unplugged my device from my computer/ the timer seems to work only reliable in sleepmode when the device is connected to my computer/ when its not connected to my computer the timer only fires correctly when the screen is on/ when it is not on it fires unpredictable at will and more often not at all/ i switched off the option that the device should not go in deep sleep when charging/ but it still works when the device is either connected to a power outlet or computer
can anyone try to explain what the reason might be?
is there anything i can do to make sure the timer is running as is should unplugged while the device is sleeping
Sorry my bad, it doesn't FULLY answer your question
One way is to register for ACTION_SCREEN_OFF and ACTION_SCREEN_ON event at the native level and propagate that event to phonegap layer (# html/js level).
More details on handling Screen Off and On intent click here.
More on how to Notify UI layer click here.
Hi I got a problem with my app. App is tracking the user road by GPS. It getting only start point and with each next point calculate distance and increase time. Everything is working great on my HTC Wildfire (with CMD7 2.3.7), Samsung SIII and Galaxy Tab 10.1.
When user start tracking, the app is finishing current activity and start new process with service in background. In the same time start new activity with small animation and put ongoing status in notification area. Everything cool, but problem starts the user is trying app on HTC one series. I can't describle how it behave, cause I don't have this phone and can't reproduce the bug.
Any of you heard anything about memory managing in HTC sense? I read some article that HTC one has this kind a feature.
Or it there is any way to test particular device on emulator?
Thanks for any help.
Make sure you are calling the Service#startForeground method to give your Service foreground scheduling priority. You can find it documented on the Service class:
http://developer.android.com/reference/android/app/Service.html
I have seen background services not get killed by using this on the One series.
i have coded my 2nd android application that switches audio profiles based on a certain schedule (date and time only as of now)....the code is working without any issues if i run the code using the emulator via eclipse...however i recently exported the apk and installed it on my At&t Samsung Galaxy S2 and added the same profile schedule as the emulator, but for some odd reason the timertask is not executing after the 1st time...
For Example:
Here is the Profile Schedule from my phone as well as the emulator:
8AM - 5:30PM -- Work
5:30PM - 10PM -- Home
10PM - 8AM -- Sleep
once the above is scheduled and i press the activate button on the main activity..a background service runs switching from one profile to the next until it is de-activated...
the only difference i have noticed between the emulator and my phone is that, the emulator screen never shuts off...so im guessing that the emulator doesnt ever go on sleep? whereas, my phone's screen turns off after about 30 seconds of inactivity, in addition to the lock screen...furthermore, i turned on USB debugging on the phone and plugged it directly into the computer and from what it seemed like, the code was executing, switching one profile to the next, on my phone without any issues...(Note that, when i was doing this testing, i used smaller time intervals in the profile schedules)...Additional details: i have also added startForeground() in my service code and ensured that the service is not getting terminated...
does anyone have any idea on what im missing, or what i can do to get around this bizarre problem?...i did do some research before posting this, and found out few posts that recommended using: Android's PowerManager...
Thanks for your input
Nothing weird about this: if the phone is asleep, the CPU is off and you cannot execute code. Don't use TimerTask on Android, use AlarmManager to schedule recurring tasks. It's implemented in the kernel and can wake up the phone if necessary (that might have a negative impact on battery life, so use with caution). Also look into WakeLock's.
http://developer.android.com/reference/android/app/AlarmManager.html