Android 中不同的系统版本隐藏和显示systemui方法

         公司最近来了一批四核的平板,刚开始以为是四核平板和二核平板的差异,导致systembar不能隐藏和正常显示。经过调查才发现,是android系统的版本问题。知道问题的所在,解决起来也就快了。

 public void showSystembar(boolean makeVisible) {
        checkInitialized();
        try {
            // get the existing environment
            ArrayList envlist = new ArrayList();
            Map env = System.getenv();
            for (String envName : env.keySet()) {
                envlist.add(envName + "=" + env.get(envName));
            }
            String[] envp = (String[]) envlist.toArray(new String[0]);
            // depending on makeVisible, show or hide the bar
            if (makeVisible) {
                Log.v(TAG, "showBar will show systembar");
                // execute in correct environment
                String command;
                Device dev = Device.getInstance();
                if (dev.getAndroidVersion() == AndroidVersion.HC) {
                    command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib am startservice -n com.android.systemui/.SystemUIService";
                //The four nucleus Tablet hide or display systemui
                } else if(dev.getAndroidVersion() == AndroidVersion.JELLYBEAN4_2) {
                    command = "su -c am startservice -n com.android.systemui/.SystemUIService ";
                //The four nucleus Tablet hide or display systemui
                } else {
                    command = "rm /sdcard/hidebar-lock\n"
                            + "sleep 5\n"
                            + "LD_LIBRARY_PATH=/vendor/lib:/system/lib am startservice -n com.android.systemui/.SystemUIService";
                }
                //The four nucleus Tablet hide or display systemui
                if(dev.getAndroidVersion() == AndroidVersion.JELLYBEAN4_2) {
                	Runtime.getRuntime().exec(command);
                } else{
                	 Runtime.getRuntime().exec(new String[] { "su", "-c", command }, envp);	
                }
                //The four nucleus Tablet hide or display systemui
                // no proc.waitFor();
                // we just shown the bar, set flag to visible
                mSystembarVisible = true;
            } else {
                Log.v(TAG, "showBar will hide the systembar");
                // execute in correct environment
                String command;
                Device dev = Device.getInstance();
                if (dev.getAndroidVersion() == AndroidVersion.HC) {
                    command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib service call activity 79 s16 com.android.systemui";
                //The four nucleus Tablet hide or display systemui
                } else if(dev.getAndroidVersion() == AndroidVersion.JELLYBEAN4_2) {
                    command = "su -c service call activity 42 s16 com.android.systemui";
                //The four nucleus Tablet hide or display systemui
                } else {
                    command = "touch /sdcard/hidebar-lock\n"
                            + "while [ -f /sdcard/hidebar-lock ]\n"
                            + "do\n"
                            + "killall com.android.systemui\n"
//                            + "sleep 1\n"
                            + "usleep 500000\n"
                            + "done\n"
                            + "LD_LIBRARY_PATH=/vendor/lib:/system/lib am startservice -n com.android.systemui/.SystemUIService";
                }
                //The four nucleus Tablet hide or display systemui
                if(dev.getAndroidVersion() == AndroidVersion.JELLYBEAN4_2) {
                	Runtime.getRuntime().exec(command);
                } else{
                	 Runtime.getRuntime().exec(new String[] { "su", "-c", command }, envp);	
                }
                //The four nucleus Tablet hide or display systemui
                // no proc.waitFor();
                // we just hide the bar, set flag to not visible
                mSystembarVisible = false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
其他的方法:

    public enum AndroidVersion {
    	//The four nucleus Tablet hide or display systemui
        HC, ICS, JB, JELLYBEAN4_2, UNKNOWN
        //The four nucleus Tablet hide or display systemui
    };

    public AndroidVersion getAndroidVersion() {
        checkInitialized();
        Log.v(TAG, "getAndroidVersion called");
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (11 <= sdk && sdk <= 13) {
            Log.v(TAG, "We are running on HoneyComb");
            return AndroidVersion.HC;
        } else if (14 <= sdk && sdk <= 15) {
            Log.v(TAG, "We are running on IceCreamSandwich");
            return AndroidVersion.ICS;
        } else if (16 == sdk) {
            Log.v(TAG, "We are running on JellyBean");
            return AndroidVersion.JB;
        //The four nucleus Tablet hide or display systemui
        } else if(17 <= sdk) {
    	    Log.v(TAG, "We are running on JellyBean4.2");
            return AndroidVersion.JELLYBEAN4_2;
        //The four nucleus Tablet hide or display systemui
        } else {
            Log.v(TAG, "We don't know what we are running on");
            return AndroidVersion.UNKNOWN;
        }
    }
记录一下。嘿嘿。。。

你可能感兴趣的:(android)