Block all means to close an android application
Asked Answered
O

5

13

I'm trying to develop an application for an android tablet.

This tablet will be shown to the public and they can touch it.

I want to block all means to close the app except for a button/preference menu that requires a password.

But after some research I am not sure if this is possible. Long press on power button still works, home button too and return button. Will this work? if so how?

Overspend answered 2/5, 2013 at 8:25 Comment(4)
why suddenly answer unaccepted ?Sty
i have just discover some new feature who make it possible but i do some test before post itOverspend
as per my knowledge we can't achieve it without user interaction , if you found way , just post code we can know .Sty
i just do it. But long text with my level in english is hard to read for native english. if you think i forgot something comment and i will try, and feel free to correct sentence who are hard to understand :POverspend
O
2

I have finally found a way to do this

No doc about this

getWindow().getDecorView().setSystemUiVisibility(8);

But the 8 is a hidden flag to completly disable system UI with this your app is permanly in full screen(Be carefull if you use this keep a way to close app) The 8 flag is completly undocumented so i can't tell you since with version this work i dev for 4.0 and 4.1 it work for both. Dunno for 3.0 but haven't any device to try it.

And don't forget android.permission.EXPAND_STATUS_BAR in your manifest

this is not perfect because if you use some alert dialogue the systemUi become visible but if you don't use any you can't quit Long press power make a powerpopup who make system ui visible too

But you can kill it fast wit the following method

public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(!hasFocus) {
    Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    sendBroadcast(closeDialog);
    }
}

If you do this you can't quit your app anymore(or i have forgot a way to close it?) so keep in mind before to make something like SureLock(app avaible on playstore), 3touch in 2 s launch an activity who ask a pass to quit it

Hope this can help and is complete

And a last question is still unanwsered Can we custom an alert view to call setSystemUiVisibility(8); because if the battery make an alert or if you think you really need an alert, this will show system UI while you alert is visible

Overspend answered 6/6, 2013 at 7:36 Comment(4)
what is your device? i can too in my galaxy tab but i have set my app as the default home so single press on home button does nothingOverspend
i'm using samsung galaxy nexusSty
And do you have time to come back to old home with recent apps key ? The goal of this method is to make a parental secure so it's a custome home as default home button can't quit thisOverspend
It does not work can you give more details how to use that code ?Skirt
E
5

you can find all the answers in already asked questions in stackoverflow

Home Button

Return Button

Power Button

Eberhard answered 2/5, 2013 at 8:31 Comment(1)
Yeah i search some but they say not possible for some that why i asked for disable all if someone know anyway to do itOverspend
P
4

At first you need to add your application as home from your manifest

<activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.settings.SETTINGS" />
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>
   </activity>

after add flag

getWindow().addFlags(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY); //(dont forget to add flag before `setContentView`)

Disable device lock

  private void disableLock() {

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

Disable home Long click

 @Override
    protected void onUserLeaveHint() {
        startActivity(new Intent(MainActivity.this,MainActivity.class));
        finish();
        super.onUserLeaveHint();
    }

After run you need to set your app to home application !!!

Prognostic answered 1/9, 2017 at 11:53 Comment(0)
R
3

I'm pretty sure this can't be done without root access to the device, in order to avoid a troll application to take control of your Android Device if you happen to run it.

Robichaux answered 2/5, 2013 at 8:29 Comment(1)
I can be root but after this app will be install on a lot of device and i don't know if all root procedure can be done by client...Overspend
O
2

I have finally found a way to do this

No doc about this

getWindow().getDecorView().setSystemUiVisibility(8);

But the 8 is a hidden flag to completly disable system UI with this your app is permanly in full screen(Be carefull if you use this keep a way to close app) The 8 flag is completly undocumented so i can't tell you since with version this work i dev for 4.0 and 4.1 it work for both. Dunno for 3.0 but haven't any device to try it.

And don't forget android.permission.EXPAND_STATUS_BAR in your manifest

this is not perfect because if you use some alert dialogue the systemUi become visible but if you don't use any you can't quit Long press power make a powerpopup who make system ui visible too

But you can kill it fast wit the following method

public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(!hasFocus) {
    Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    sendBroadcast(closeDialog);
    }
}

If you do this you can't quit your app anymore(or i have forgot a way to close it?) so keep in mind before to make something like SureLock(app avaible on playstore), 3touch in 2 s launch an activity who ask a pass to quit it

Hope this can help and is complete

And a last question is still unanwsered Can we custom an alert view to call setSystemUiVisibility(8); because if the battery make an alert or if you think you really need an alert, this will show system UI while you alert is visible

Overspend answered 6/6, 2013 at 7:36 Comment(4)
what is your device? i can too in my galaxy tab but i have set my app as the default home so single press on home button does nothingOverspend
i'm using samsung galaxy nexusSty
And do you have time to come back to old home with recent apps key ? The goal of this method is to make a parental secure so it's a custome home as default home button can't quit thisOverspend
It does not work can you give more details how to use that code ?Skirt
S
0

Simply you can't do this , you can't stop user to pressing Home Button

you can block Back press event .

You can stop user from pressing home Button using onAttachedToWindow() but this may not work from android 3.2

Sty answered 2/5, 2013 at 8:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.