This solution will work forallversions of Android. You can use reflection in Java to make it work for all Android devices:

Basically you should create a reflection wrapper to call the Android 2.2 setDisplayOrientation, instead of calling the specific method.

The method:

  protected void setDisplayOrientation(Camera camera, int angle){   Method downPolymorphic;   try   {     downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class });     if (downPolymorphic != null)       downPolymorphic.invoke(camera, new Object[] { angle });   }   catch (Exception e1)   {   } } 

And instead of usingcamera.setDisplayOrientation(x)usesetDisplayOrientation(camera, x):

  if (Integer.parseInt(Build.VERSION.SDK) >= 8)     setDisplayOrientation(mCamera, 90);   else   {     if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)     {       p.set("orientation", "portrait");       p.set("rotation", 90);     }     if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)     {       p.set("orientation", "landscape");       p.set("rotation", 90);     }   } 

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android中下拉列表框操作
  2. android 脸部抠图
  3. Android(安卓)项目混编flutter报错
  4. Android回调事件传播-android学习之旅(四
  5. Android之常用功能代码
  6. android软键盘问题
  7. android 颜色采摘
  8. Android(安卓)MediaPlayer Error (-38, 0
  9. android out of memory(OOM)
  10. Android图片圆角处理