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?
To block app installations on Android devices, admin can navigate to Android Profile -> Restrictions -> Applications -> Users can install unapproved apps.
The truth is you do not need to kill Android apps. In fact, closing apps can make things worse. It's unclear where this idea came from, but it's been present on Android since the very beginning. “Task Killer” apps were very popular in the early days.
Closing the apps on your phone makes it run faster and drain your battery slower. By Sarah Chaney. May 4, 2022. It doesn't close the app when you back out of an app on your Android device. It runs in the background if you need to bring it up again quickly.
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 !!!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With