据我所知,尚无官方方法可以执行此操作,因为它可能被恶意使用,但这就是我实现此目标的方法.它是通过无礼地杀死处理Nav / Action条等的系统服务来工作的.粗暴但它是我唯一能找到的可行方法.
这将阻止所有导航按钮,操作栏等.我不知道仅停止其中一个的方法
在主活动中将hideNav()称为onCreate,并从onDestroy调用showNav(),如果您想让管理员访问操作系统,则需要使用该方法,因为除非您专门重新启动服务,否则您将无法浏览设备.
我的应用程序有一个退出按钮,只能使用密码才能访问.该按钮调用getActivity().finish(),您将需要调用该活动的onDestroy方法.
注意:我已阅读到某些设备上的systemui服务并不总是42,因此您的平板电脑在命令中可能需要其他数字.
public void hideNav()
{
Log.v(tag, "hideNav");
try
{
Process p;
p = Runtime.getRuntime().exec("su");
// Attempt to write a file to a root-only
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("service call activity 42 s16 com.android.systemui
");
// Close the terminal
os.writeBytes("exit
");
os.flush();
p.waitFor();
}
catch (Exception e)
{
Log.e(tag, "hideNav " + e.getMessage());
}
}
public void showNav()
{
Log.v(tag, "showNav");
try{
Process p;
p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("am startservice -n com.android.systemui/.SystemUIService
");
// Close the terminal
os.writeBytes("exit
");
os.flush();
p.waitFor();
}catch (IOException e) {
e.printStackTrace();
Log.e(tag, "showNav " + e.getMessage());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Log.e(tag, "showNav " + e.getMessage());
}
}