我开发使用Android的向后代码兼容性
android.hardware.Camera.parameters.getSupportedPictureSizes()
这只能从SDK版本8,我想一个应用程序后与SDK 4兼容,所以我这样做:
如果(Build.VERSION.SDK_INT> = 8){...}
但在模拟器上,它煤层,它试图检查参考这个功能,它失败:
11月2日至2日:20:10.930:ERROR/dalvikvm(1841):找不到方法android.hardware.Camera $ Parameters.getSupportedPictureSizes,从方法com.test.demo.CameraCustom.takeAPicture
有关如何解决这个向后兼容性问题的任何想法引用?
我试着用这段代码在surfaceChanged里面使用这个代码。显然,代码工作的情况下直接invokation:
try{
windowmanager_defaultdisplay_Rotation = getWindowManager().getDefaultDisplay().getClass().getMethod("getRotation");
Log.v(MainMenu.TAG, "getRotation exist");
}catch(Exception e){
Log.v(MainMenu.TAG, "getRotation dont exist");
}
try{
windowmanager_defaultdisplay_Rotation.invoke(null, null);
Log.v(MainMenu.TAG, "getRotation invoking ok, rotation ");
}catch(Exception e){
Log.v(MainMenu.TAG, "exception invoking getRotation "+e.toString());
}
我得到“getRotation存在”但随后“异常调用getRotation显示java.lang.NullPointerException
任何想法
是的,我认为我应该这样做:http://developer.android.com/resources/articles/backward-compatibility.html,谢谢! – zegnus 2011-02-02 16:24:58