码迷,mamicode.com
首页 > 移动开发 > 详细

android虚拟键盘disable与enable

时间:2018-06-20 12:59:07      阅读:359      评论:0      收藏:0      [点我收藏+]

标签:try   pac   apk   ted   xmlns   exception   hide   share   get   

  • 代码如下
    /**
     * AndroidUSBCamera-master
     * Created by lzw on 2018/6/20. 10:53:22
     * 邮箱:632393724@qq.com
     * All Rights Saved! Chongqing AnYun Tech co. LTD
     */
    public class ShieldUtil {
        public static final String STATUS_BAR_SERVICE = "statusbar";
        public static final String CLASS_STATUS_BAR_MANAGER = "android.app.StatusBarManager";
        public static final String METHOD_DISABLE = "disable";
        public static final String METHOD_ENABLE = "enable";
    
        public static void hideKeys(Context context){
            try {
                @SuppressLint("WrongConstant") Object service = context.getSystemService(STATUS_BAR_SERVICE);
                Class<?> statusBarManager = Class.forName(CLASS_STATUS_BAR_MANAGER);
                Method disable = statusBarManager.getMethod(METHOD_DISABLE,
                        int.class);
    //          disable.invoke(service, 0x00200000); // 为View.STATUS_BAR_DISABLE_HOME 的值
    //          disable.invoke(service, 0x00400000); // 为View.STATUS_BAR_DISABLE_BACK  的值
                disable.invoke(service,  0x00200000|0x01000000); // 为View.STATUS_BAR_DISABLE_RECENT的值
    
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static void showKeys(Context context){
            try {
                @SuppressLint("WrongConstant") Object service = context.getSystemService(STATUS_BAR_SERVICE);
                Class<?> statusBarManager = Class.forName(CLASS_STATUS_BAR_MANAGER);
                Method disable = statusBarManager.getMethod(METHOD_DISABLE,
                        int.class);
    
                disable.invoke(service,  0x00000000|0x00000000); // 为View.STATUS_BAR_DISABLE_RECENT的值
    
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    

      

  • 注意:只能在有系统权限下使用,也就是在AndroidManifest.xml里面有
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        android:sharedUserId="android.uid.system"
        package="com.jiangdg.usbcamera">
    

      

  • 需要有权限
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
    

      

  • 所以这就决定了只能再自己有源码不是定制android系统的设备上有效果

android虚拟键盘disable与enable

标签:try   pac   apk   ted   xmlns   exception   hide   share   get   

原文地址:https://www.cnblogs.com/endian11/p/9202929.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!