Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Screen Lock(Power) Button in Android

I want that when my application is running the power button (which upon pressing locks the screen & screen goes BLACK), should be disabled. So that the user cannot lock the screen.

I have noticed this thing in Samsung Galaxy S phone's Default Camera App. That's the same reason I am trying to do the same. I have also a Camera related App.

like image 866
Khawar Avatar asked May 30 '12 13:05

Khawar


People also ask

How do you turn off lock instantly with power button?

From the Home screen, tap Apps > Settings > Lock screen. Tap Power button instantly locks to checkmark and enable the device to instantly lock the screen by pressing the Power/Lock Key or remove the checkmark to disable it.

How do I remove the power menu from the Lock screen?

Thankfully, a simple app on the Play Store — Smart Lockscreen Protector — can fix this issue for you. The app completely blocks the Power menu from appearing on the lockscreen, thus preventing anyone from switching off or putting your device in Airplane/Silent mode. The best part? It does not require root to work.

How do I lock my phone screen without the power button?

To lock your phone without a power button, try double-tapping your screen. Many modern Android devices have a double-tap to unlock and lock feature available.


1 Answers

try this one

int val=android.provider.Settings.System.getInt(getContentResolver(),
                                                                SCREEN_OFF_TIMEOUT);

                    android.provider.Settings.System.putInt(getContentResolver(),
                                                            SCREEN_OFF_TIMEOUT, -1);
                    Toast.makeText(this, "Disabled Screen Timeout", Toast.LENGTH_LONG).show();
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putInt("ScreenTimeout",val);
                    editor.commit();
                }
            } catch(Throwable er) {
                Toast.makeText(this, "Error "+er.getMessage(), Toast.LENGTH_LONG).show();
            } 

that will set screen off

to disable key guard in android use

KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();

and use permition

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

to keep screen alive

 @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
like image 153
UdayaLakmal Avatar answered Oct 04 '22 06:10

UdayaLakmal