使用的ionic工程,重点是3,4方法;
找到了几种方法:
1、
获取StatusBarManager实例
mStatusBarManager = (StatusBarManager) mContext.getSystemService(Context.STATUS_BAR_SERVICE);1
禁止下拉和解除禁止
mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND); //禁止下拉
mStatusBarManager.disable(StatusBarManager.DISABLE_NONE); //解除禁止
报错:无法引入StatusBarManager
参考:https://stackoverflow.com/questions/11323637/why-cant-i-find-a-reference-to-the-statusbarmanager-class-directly
2、
//只能全屏,无法阻止下拉,用cordova插件就可以完成全屏了
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
3、是1方法延伸,使用反射调用;
Object service = getSystemService("statusbar");
try {
Class<?> statusBarManager = Class.forName
("android.app.StatusBarManager");
Method expand = statusBarManager.getMethod("disable", int.class);
expand.invoke(service, disable_status);
} catch (Exception e) {
//unBanStatusBar();
//e.printStackTrace();
}
具体参考:https://blog.csdn.net/qq_26819733/article/details/52203783
这个方法缺陷:android5.0以上会报错:
Caused by: java.lang.SecurityException: StatusBarManagerService: Neither user 10290 nor current process has android.permission.STATUS_BAR
无法获取到权限;
办法:app运行时请求权限
参考:https://stackoverflow.com/questions/32742327/neither-user-10102-nor-current-process-has-android-permission-read-phone-state
4、使用这个插件:https://github.com/hkalina/cordova-plugin-kiosk
网友评论