diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java index 40dd7050e95..308e438a95d 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -421,24 +421,29 @@ protected void hideVirtualButton() { // use reflection to remove dependence of API level Class viewClass = View.class; - final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION"); - final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN"); - final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION"); - final int SYSTEM_UI_FLAG_FULLSCREEN = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_FULLSCREEN"); - final int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_IMMERSIVE_STICKY"); - final int SYSTEM_UI_FLAG_LAYOUT_STABLE = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_STABLE"); - - // getWindow().getDecorView().setSystemUiVisibility(); - final Object[] parameters = new Object[]{SYSTEM_UI_FLAG_LAYOUT_STABLE - | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar - | SYSTEM_UI_FLAG_FULLSCREEN // hide status bar - | SYSTEM_UI_FLAG_IMMERSIVE_STICKY}; - Cocos2dxReflectionHelper.invokeInstanceMethod(getWindow().getDecorView(), - "setSystemUiVisibility", - new Class[]{Integer.TYPE}, - parameters); + + try { + final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION"); + final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN"); + final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION"); + final int SYSTEM_UI_FLAG_FULLSCREEN = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_FULLSCREEN"); + final int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_IMMERSIVE_STICKY"); + final int SYSTEM_UI_FLAG_LAYOUT_STABLE = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_STABLE"); + + // getWindow().getDecorView().setSystemUiVisibility(); + final Object[] parameters = new Object[]{SYSTEM_UI_FLAG_LAYOUT_STABLE + | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar + | SYSTEM_UI_FLAG_FULLSCREEN // hide status bar + | SYSTEM_UI_FLAG_IMMERSIVE_STICKY}; + Cocos2dxReflectionHelper.invokeInstanceMethod(getWindow().getDecorView(), + "setSystemUiVisibility", + new Class[]{Integer.TYPE}, + parameters); + } catch (NullPointerException e) { + Log.e(TAG, "hideVirtualButton", e); + } } } diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java index c53b2690144..a6b725733b8 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java @@ -1,6 +1,6 @@ /**************************************************************************** Copyright (c) 2010-2012 cocos2d-x.org -Copyright (c) 2013-2014 Chukong Technologies Inc. +Copyright (c) 2013-2016 Chukong Technologies Inc. http://www.cocos2d-x.org @@ -130,9 +130,12 @@ public static void init(final Activity activity) { parameters = new Object[]{Cocos2dxReflectionHelper.getConstantValue(audioManagerClass, "PROPERTY_OUTPUT_FRAMES_PER_BUFFER")}; final String strBufferSizeInFrames = Cocos2dxReflectionHelper.invokeInstanceMethod(am, "getProperty", new Class[]{String.class}, parameters); - sampleRate = Integer.parseInt(strSampleRate); - bufferSizeInFrames = Integer.parseInt(strBufferSizeInFrames); - + try { + sampleRate = Integer.parseInt(strSampleRate); + bufferSizeInFrames = Integer.parseInt(strBufferSizeInFrames); + } catch (NumberFormatException e) { + Log.e(TAG, "parseInt failed", e); + } Log.d(TAG, "sampleRate: " + sampleRate + ", framesPerBuffer: " + bufferSizeInFrames); } else { Log.d(TAG, "android version is lower than 17");