Disable Screen Lock(Power) Button in Android
Asked Answered
T

2

10

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.

Tanika answered 30/5, 2012 at 13:31 Comment(1)
how did you solve this?Mozellemozes
R
8

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);
    }
Reprehensible answered 30/5, 2012 at 13:36 Comment(5)
in order to use that need <uses-permission android:name="android.permission.WRITE_SETTINGS" />Reprehensible
I am not looking for TIMEOUT. I am talking about Disable POWER BUTTON.Tanika
i noticed that later, i did change my answerReprehensible
Thanks for your answer, I see that the phone is not locked now but the screen is still going black. How can we avoid this? Anyways I am voting up for your answer. Thanks.Tanika
i added code into below the answer, try that out getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);Reprehensible
S
3

I have reached this using root access.

sqlite3 /data/data/com.android.providers.settings/databases/settings.db
insert into secure (name, value) values ('lockscreen.disabled', 1);

or depending on version

sqlite3 /data/system/locksettings.db
insert into locksettings (name, value) values ('lockscreen.disabled', 1);
Seal answered 17/4, 2014 at 14:24 Comment(1)
i am not understand . can you brief to me please.Drillstock

© 2022 - 2024 — McMap. All rights reserved.