Removing Android navigation and topbar,

China☆狼群 提交于 2019-12-11 04:56:06

问题


I am trying to implement a Kiosk app on a rooted android device, and I need to disable the navigation and status bar completely.

These commands works from adb shell

Disable:

service call activity 42 s16 com.android.systemui

Enable:

am startservice -n com.android.systemui/.SystemUIService

That's good! Now I need to be able to do it from my app. So to disable I've tried:

Process process = Runtime.getRuntime().exec("su service call activity 42 s16 com.android.systemui");

when pressing a button in my activity. But nothing happens, and no exceptions are thrown. A toast pops up though, saying that the app has been given super user rights.

Any ideas?


回答1:


To run su cmd you can use this

public static void runCmd(String cmd) {
    DataOutputStream os;
    try {
        Process process = Runtime.getRuntime().exec("su");
        os = new DataOutputStream(process.getOutputStream());
        os.writeBytes(cmd + "\n");
        os.writeBytes("exit\n");
        os.flush();
        os.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

To disable system ui you can run this command

runCmd("pm disable com.android.systemui && service call activity 42 s16 com.android.systemui");

If you want to enable back

runCmd("pm enable com.android.systemui && am startservice -n com.android.systemui/.SystemUIService");



回答2:


With Android 5 and 6, you can try this trick:

settings put secure user_setup_complete 0



回答3:


Split su call and command call :

try{
    Process su = Runtime.getRuntime().exec("su");
    DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

    outputStream.writeBytes("service call activity 42 s16 com.android.systemui");
    outputStream.flush();

    outputStream.writeBytes("exit\n");
    outputStream.flush();
    su.waitFor();
}catch(IOException e){
    throw new Exception(e);
}catch(InterruptedException e){
    throw new Exception(e);
}


来源:https://stackoverflow.com/questions/41856557/removing-android-navigation-and-topbar

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