Android Wear - Show watchface while ambient, app while active - android

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.

Related

android service foreground screen lock mode

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.

Audio Call Stops working when Android App goes in Background and device is on Battery Saver Mode

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

How to disable/enable screen rotation from an android SERVICE?

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.

Prevent my app to sleep when device goes to sleep mode

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);

How to access camera or gallery in android Kiosk Mode app?

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

Categories

Resources