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.
Related
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.
I am developing a Fitness Application as part of my Bachelor Thesis, and want to keep track of step counts even when the application is completely closed. For this I am currently starting a service that utilises the built in Sensors "Step Counter" and "Step Detector". After some testing I found out that sometimes my Service gets killed and no longer keeps track of the steps taken. I left the phone on my desk overnight and walked around in the morning then I opened the application and the steps I took in the morning were not tracked, whereas when I close the application and immediatly start walking the tracking of steps still works.
Is there a way to make sure that my Service does not get killed?
Would the use of a Foreground Service solve my issue and are there any alternatives to using a foreground service?
Foreground Service is the only way if you want to assure that the service will not be killed.
The reason for this is that the foreground service always shows a notification to the user and can be killed by the user if he wants to, this is especially important if you want to know for sure what runs on your device.
All previous methods of making permanent running services are deprecated starting from android 9, when a new privacy policy was introduced.
Basically you need to keep service running in the background,
Here is the workaround to achieve this
https://stackoverflow.com/a/58162451/7579041
above link is useful for Stock ROM & Custom ROM Devices like OnePlus, OPPO, VIVO, etc
I hope this will help you out
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.
some context:
I have an alarm app I use for myself that locks the screen when the alarm goes off for the duration you request prior. Essentially your phone is a ringing brick for x minutes. The only problem is my sleepy self is very irrational and in the morning I figured out that if I turn off the phone and get to the app location and uninstall it before the receiver gets called (boot completed) then I can bypass it bricking my phone. This didn't use to be a big deal when my LG G2 was on 4.2.2 because of how fast the receiver was called I would usually have to restart my phone about 5-8 times to uninstall the app before it was bricked so I just gave up and quit trying. Now, I upgraded to 4.4.2 and the receiver is called about a full 10 seconds later letting me delete the app on the first try every time. Making the app completely useless.
What I have tried:
I have tried using quick_boot in the manifest but I believe that this is only for HTC because on_boot doesn't get called for that OS for some reason. I have also tried the user present which only seems to work after the boot is completed when doing things like unlocking your phone.
Is there really no way to make onReceive be called quicker than onBoot? It would make sense if there isn't , I'm just hoping someone could provide a definite answer either way.
In some cases it is. I'm not 100% sure but i think (some) systemapps have higher priority then the ACTION_BOOT_COMPLETED event. AND there is ACTION_SCREEN_ON which should be triggered before ACTION_BOOT_COMPLETED.
I should have answered this a week or so after I asked this question because I found a pretty useful workaround, although, it is a little sloppy.
I made a new activity(homeLock) with the intent filter . homeLock extends activity and my old main activity(alarmMain) extends homeLock now instead of activity. All homeLock does is start the overlay service(so you can't stop the alarm/use the phone) that will be turned off by alarmMain when it determines whether an alarm should be ringing currently or not. In alarmMain there is a button now that says "change home" which lets you make homeLock the home application. Now, when you turn off the phone and restart to try and delete the application before onBootReceived is called which starts the broadcast receiver(triggers alarm and overlay) the homeLock activity is called which puts an overlay on the screen until it can be removed after the application determines if an alarm should be playing or not (after onBootReceived).
Basically, before you go to sleep just set this application as your home application from within the app or through settings. Now, it should be impossible to delete the application or turn off the alarm once it has started ringing until it has rung its duration because there will always be an overlay on the screen even when restarting the phone.
Obviously this addition is only needed for phones that boot slowly or extremely degenerate sleepers, or both like me. While it is unlikely this will help anyone because it is such a unique problem I thought I should post the workaround I have been using just in case someone does end up finding it useful.
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