问题
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