Tested on ~20 Samsung Tab 4 8.0 (SM-T330NU) running 4.4.2 but unfortunately no other devices.
If the tablet already has the extremely extremely obnoxious Samsung demo mode you'll need to do a factory reset. Go to Samsung demo settings from the notification tray, first password is 5444
, admin password to factory reset is M729Q16K8546
.
Enable Development options by going to Settings -> General -> About device and tapping on the Build number ~8 times. When development options appear enable USB debugging (Stay awake is also a option to enable for a kiosk.)
Install Towelroot, launch it and click the magic button. You now have root and can uninstall Towelroot. This will allow us to completey remove the top bar later.
Disable the lock screen (under device settings.) Also maybe take this opportunity to disable other features that don't make sense for a kiosk such as
- touch sounds
- keyboard sound when tapped
- palm motion
- smart screen
- software update (wouldn't want to lose root access.)
A proof of concept strongly locked down kiosk activity, the heart of it is stopping the systemui process (and starting it up again when we finish.)
One bug with this technique is it does make your wallpaper black until a reboot. Not really an issue for my use case.
package io.kate.android.kiosk;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
public class KioskActivity extends Activity {
public final String TAG = KioskActivity.class.getName();
Boolean allowLeavingActivity = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
hideSystemBar();
// an view that lets you go to settings page when you long press
final View escapeButton = (View) findViewById(R.id.button_escape);
escapeButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
showSystemBar();
allowLeavingActivity = true;
// put the user close to where they can disable this app as the default home application
Intent intent = new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
startActivity(intent);
finish();
return true;
}
});
}
@Override
protected void onResume() {
super.onResume();
allowLeavingActivity = false;
}
@Override
protected void onPause() {
super.onPause();
// boomerang right back to us, requires android.permission.REORDER_TASKS
if (!allowLeavingActivity) {
ActivityManager activityManager = (ActivityManager) getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.moveTaskToFront(getTaskId(), 0);
}
}
@Override
public void onBackPressed() {
// allow the back button to close the soft keyboard
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
// kills the systemui process, this will also cause the wallpaper to disappear
public void hideSystemBar() {
runShellCommand(new String[]{"su","-c","service call activity 42 s16 com.android.systemui"});
}
public void showSystemBar() {
runShellCommand(new String[]{"su", "-c", "am startservice --user 0 -n com.android.systemui/.SystemUIService"});
}
private void runShellCommand(String[] commands) {
try {
Process proc = Runtime.getRuntime().exec(commands);
proc.waitFor();
} catch(Exception ex) {
Log.e(TAG, ex.toString());
}
}
}
In your AndroidManifest the app will need android.permission.REORDER_TASKS
permission and the activity will need android.intent.category.LAUNCHER
and android.intent.category.HOME
categories.
When you run the KioskActivity for the first time, exit and tap the home button, in the dialog that appears select your app and always. Now the KioskActivity will be launched even after a reboot.
When you no longer want to use the KioskActivity use the escape button to get to settings, go to default applications and clear.