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.
My question is more like client side.
I am using Janus AudioBridge Room to make audio call.
Android app works fine in foreground and background mode if device is not on Batter saver mode.
But when device is in Battery saver mode. App gets hold while getting into background.
When we gets back to the app. Call rejoins from there. But if it gets long enough to call 'Keepalive' event. Then app will stops or crash.
I handle this by getting this android permission explicitly from user.
"android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"
Then in battery saver mode. our call does not affects. as our app now can work on background in battery saver mode also.
I don't think this is the best way to do that.
I checked Whatsapp permissions. They are not asking for it.
What Whatsapp or other calling applications are doing to do this in a more proficient way?
Any guide and Clue will be helpful. I appreciate
During some period that an android service is running the screen rotation needs to be disabled.
Is there any way to disable/enable the screen rotation from an android service?
You can imagine that what may happen if service controls the mode of device - there may be an app's activity who requested or need a landscape mode because user has rotated the device but the service (which is running in background) which user has no idea, is forcing the portrait mode for the device, even though user rotated device for landscape experience - not good for overall user experience.
Hence, AFAIK, the android:screenOrientation option which controls the landscape/portrait mode, is applicable to Activity class only & not to the Service.
Since Service's job is to run in background it typically does not contain any UI & hence options such as how the UI elements are to be display i.e in landscape or portrait mode is not the role of Service.
I have written an app that should be running continually event if device goes to sleep mode.I have tried many things like services (with startForground also) , alarm manager and persistant="true", but when device go to sleep (by user or by device) , my app is terminated.and even PowerManager does not work too.
There is an option in device setting that is 'Keep running after screen off' (in huawei device : setting > app > my app options > battery > Keep running after screen off). So when this option is active , the app is running for ever.I want implement something like this in my app programitically.
I saw some apps that implemented this , but I dont know how.
So how can I do that?
Use ForgroundService.
If you check your device applications with an app manager, you can see that some of them using a sevice that is always running. even if you stop them, some of them start working again.
see more about services behavior in android developer.
and search for "keeping a service alive".
On some devices (Huawei, Xiaomi, LG) there is a special setting that contains a list of apps that are allowed to run in the background. It sounds like you are talking about trying to accomplish the same thing. This cannot be done on those devices. On those devices, unless your app is added to the list of apps that are allowed to run in the background ("Protected Apps" on Huawei), the Android framework will not restart your app if it is shutdown. There is no way for you to programatically add your app to this list, and there is no way for you to work around this feature.
Certain apps need to keep the screen turned on, such as games or movie apps. The best way to do this is to use the FLAG_KEEP_SCREEN_ON in your activity (and only in an activity, never in a service or other app component).
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
i am using kiosk mode in my android app. Here kiosk service should be called every two second and the app open for every two seconds. My app needs to access gallery or camera app. But my app does not let me access these things because every two seconds it comes to foreground if we try to go to other applications. Now my problem is i need to access camera and gallery in kiosk service which should be called for every two seconds.
Afaiu you are using background service which runs continuously in gap of 2 second.
Instead of using background service i would suggest you should use screen pinning option for android lollipop or more devices. To get more information regarding this you can read http://www.sureshjoshi.com/mobile/android-kiosk-mode-without-root/ .
Also ,you have to make your application a launcher application,so that everytime user presses the launcher icon your application starts.
To disable power on/off button you can use System Dialog Disable feature.
By using this you can get following benefits :-
1) Power consumptions/Memory usage is minimized.
2) According to your usage you can disable/enable the kiosk mode.
3) You can start the other application from your application by disabling the kiosk mode application.
Regards
Ajay