Prevent screen lock on dimming/standby while using android app? - android

I'm developing an application and the last touch I need to put on it is preventing the screen to lock when the device goes into standby (screen off). The exact behavior as Google Navigation.
I'm wondering what, programatically I will have to use to keep this feature enable the entire time while using the app?

writing the following code to your xml file will prevent the screen from locking
android:keepScreenOn="true"

In the onCreate of your activity after the setContentView use this:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Not tried it myself.

Related

How to put my app icon on locked screen in android

I am developing a security app. So its necessary for me to put it on lock screen. Is there a way to put it on lock screen? so that user can interact directly when needed.
For devices with lockscreens that support app widgets, you can write an app widget that can be placed on the lockscreen.

How to prevent an Android application from locking?

I am currently making an Android application in which I need the phone to not lock, so as to avoid the activity losing focus.
I have done a bit of research and found numerous ways to do it including the use of:
Keyguard Manager
Power Manager
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
android:keepScreenOn="true"
I tried using the android:keepScreenOn="true" in my Android manifest, but it seemed to have no effect on the application. I am hesitant to using power manager as every post about it is filled with numerous warnings.
In closing, what is the best way to prevent the Android phone from locking and losing focus of the application? The screen itself may dim or turn off, so long as the application remains in focus and the phone doesn't lock.
What you want can easily achieved by using the PowerManager with a Screen Dim Wake Lock.
Also, IIRC, keepScreenOn is supposed to be added to a widget in an XML file, not in the manifest, if you do decide to use that in the end.

How to control the Screen Power Saver mode?

In my application i want add this feature .
After open the application before closing the application i don't want allow to go into the power saver mode of the device. How can i manage this. even user can't doing anything on the screen (even it is in idle). after closing my application allow to get power saver mode.
Edit i got the solution for this Query..
Use this keyword for your layout:
FLAG_KEEP_SCREEN_ON
add this code
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Stop android device from sleeping

I'm trying to develop a very simple app that displays like a slideshow of images which Im sure ill be able to figure out (if anyone has any advice would be much appreciated) but what im wondering is there any way I can stop the device from going to sleep if its left cycling through these images?
using
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
will make the screen always on which will disable the lock. Remove it by using
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Add android:keepScreenOn="true" to some widget in your activity's layout XML file. While the activity is in the foreground, the device will not fall asleep.
You would use a wake lock.
http://developer.android.com/reference/android/os/PowerManager.WakeLock.html

How can I stop auto screen rotation in my Android app when unlocking the phone from standby

I have an android application that I want to always be running in landscape mode.
I have the following code implemented to keep the app in landscape mode all the time:
inside my activity in the Application Manifest
android:screenOrientation="landscape"
This seems to launch and keep the application in landscape view for the whole duration of the application. Perfect!
However, if I have the app running on my HTC Aria (Android 2.1) and the phone locks, if I unlock the phone, I see the application for probably half a second and it's in portrait orientation and then quickly switches back to landscape mode. It is quite frustrating because all of my views are jumbled around and it looks unprofessional as you can imagine. This happens in both the emulator and on my real phone.
Does anyone know how to stop the application from temporarily rotating when the phone is unlocked?
Additions:
I have tried overriding onConfigurationChanged() but with no success.
I have also tried putting setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); into the onResume() but the app still shows as the incorrect orientation for a split second when the phone is unlocked.
Try setting the orientation in the manifest file. it might just work.
After looking at many other apps that are made for landscape orientation only, I can see that their apps don't freeze their orientation after standby either. I have a feeling that this is a limitation of the phone, and that all apps will switch to a portrait orientation when the phone is locked. If all apps have this "problem" then I think it is acceptable not to fix.
Please post if you have found out there is a way to stop the forced portrait orientation.
the app still shows as the incorrect orientation for a split second when the phone is unlocked.
Did you move setContentView(R.layout.main) to the onResume, AFTER where you put your orientation code? I would try setting the orientation, then the setContentView()

Categories

Resources