Can I disable systemui From within my android app?

烈酒焚心 提交于 2019-12-30 04:34:10

问题


I used this answer to achieve a Kiosk Mode for my app: https://stackoverflow.com/a/26013850

I rooted the tablet with Kingo Root and then performed the following commands:

adb shell >
 su >
 pm disable com.android.systemui >

I am building an app that will only be used on our devices as kiosks....

It works great BUT.. I would like to perform the disable and enable of the system ui from the Android application itself.

Are system commands possible from within an application?


回答1:


/**
 * Uses Root access to enable and disable SystemUI.
 * @param enabled Decide whether to enable or disable.
 */
public void setSystemUIEnabled(boolean enabled){
    try {
        Process p = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(p.getOutputStream());
        os.writeBytes("pm " + (enabled ? "enable" : "disable") 
                + " com.android.systemui\n");
        os.writeBytes("exit\n");
        os.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Works fine. Usage:

setSystemUIEnabled(true);  // Enable SystemUI
setSystemUIEnabled(false); // Disable SystemUI


来源:https://stackoverflow.com/questions/28055413/can-i-disable-systemui-from-within-my-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!