I need to detect when the android smartphone goes into lock screen mode and when it comes out.
I need it to be able to bring a service respectively in start foreground and stop foreground so that the location sensor continues to work both when the smartphone is off (on lock screen) and when it is on.
Is there a fast way to do this detection without having to use the kastri library?
Prefer not to be dependent on the kastri library. That's why I asked for this.
Related
I have a utility app that changes the screen (much like a night screen type app) and I wanted to add a whitelist to bypass the night light when certain apps are in use.
I have found how to view what the current foreground app is but I dont know how to tell when the foreground app changes, aside from checking every 5 seconds which I dont want to do as it would be quite heavy.
Is there any way with a foreground service to monitor foreground app changes?
Im using Zebra TC25 DWDemo profile for our app, after enabling broadcast intents for bar code reads. all works well when my app is on the foreground and the screen is on. but once i close the screen with the device power button it stops getting broadcasts and the scanning barcode hardware is not responding. (the red laser read lights dont respond to clicks on the side buttons anymore).
I made sure to successfully acquire a partial wake lock (by logging mssgs on logcat while the device screen is off) and have registered a WakeFullBroadcastReceiver for getting the hardware's broadcast intents.
What to do in order to keep the hardware active and getting barcode reads and broadcasts to my app while device's screen is off and the CPU is kept awaken?
The DWDemo app is using DataWedge to capture scan data, specifically the 'DWDemo' profile and you can see this if you go to the settings screen from within the app. DataWedge is a separate service on the device and just because your app has a partial wake lock I'm pretty sure that does not prevent the DataWedge service from still sleeping when the screen turns off, plus you would need to consider other scenarios like the device entering doze mode and clearing existing wake locks. DataWedge is designed primarily to change the scanner configuration when different applications appear in the foreground; when the screen turns off the app goes to the background as far as Android is concerned so DataWedge would also likely switch out of the 'DWDemo' profile anyway.
For your needs I think it would make more sense to access the scanner directly via the native SDK, EMDK which is available for both Android (Java) and Xamarin. Another future option I notice is Zebra are introducing a 'Wakeup sources' parameter (http://techdocs.zebra.com/mx/powermgr/#wake-up-sources-enabledisable) however that requires MX8.0+ which is not (yet?) available for TC2x since MX8.0+ would require Oreo, based on the naming.
For clarity, I work for Zebra.
I'm designing an android app for my wearable device in which I have overridden ambient mode. I would like for my app to show the watchface while in ambient mode, and show the app while out of ambient mode. In other words, I want to make the app "invisible" while ambient mode is on. (Note that keeping the activity in the foreground while this is happening is desirable!)
I have looked but haven't found a way to show the watch face while the app is open. Can anyone direct me to some sources/provide an explanation as to how one might accomplish this?
I'm not sure why you want to keep the activity in the foreground when the watch is in ambient mode, but I think there's a better way to do it:
1) If you want your app to keep doing something (read from sensors etc) while in ambient mode, use a Service instead.
2) If you just want to keep the state of your activity, save it to a Bundle and use that to repopulate the UI when the app is launched again.
Keeping the activity alive when it's not shown is a waste of both memory and battery.
I suggest changing your activity to only show in interactive mode. Let the system kill it when the device goes into ambient mode. Then your watch face will be displayed automatically. You can launch the app again from your watch face when interactive mode is triggered.
I am running an accelerometer based android app that will run for a few months while phone is on and does nothing else. Some phone allow display not to go to sleep at all which allows my app run fine infinitely. The screen also has only a black display and nothing else apart from background accelerometer listener and occasional http posts. My question is if I remove the display screen while the app is running, would that stop the operating system and/or my app?
My question is if I remove the display screen while the app is running, would that stop the operating system and/or my app?
In short, it depends on your app architecture (otherwise i.e. music players would require to keep screen on to work). Depending on task you are really doing you may use Alarm Manager to periodically fire your code, or use Service.
I'm developing an app which requires the system to get the touch events even after the system goes to sleep mode or after the user locks the screen, I tried searching for a solution but it is hard to find one.
Should I want to set any permissions or is there any inbuilt methods or can I override any methods to perform this functionality.
I'm developing an app which requires the system to get the touch events even after the system goes to sleep mode or after the user locks the screen
Fortunately, this is not possible. Otherwise, the device would not be asleep, and battery life would suffer as a result.
Here is a link that shows how to prevent the phone from sleeping.
If you couple that with, say a black screen to 'pretend' the hone is sleeping but actually running your code. So your code can still intercept touch event
Then you need to install your app as a service and make it start when the device is turned on.
You will not need NDK or rooted device for that (sorry, got a short night :) )