Intergrate camera without deprecated methods and backwards support

安稳与你 提交于 2019-12-12 12:15:08

问题


I want to build an application where the front camera of the device is used to project the current image to a SurfaceView. All the tutorials I found so far implement this by using a Camera object from the android.hardware package.

This method, however, seems to be deprecated. When trying the 'new' preferred way to implement this feature following the Android documentation, I get the warning it can only be used with API level 21, which is pretty useless.

So I would like to know the currently preferred way to implement camera functionality in an application. Or is there maybe some support library for API levels lower than 21?

Thanks in advance.


回答1:


Deprecated interface does not mean you should not use it. It means you should know that it will be phasing out in the future.

As a general rule, it is better to use a newer interface if possible, in order to avoid the need to update the software later.

The fact that API level 21 does not yet have a large enough market share means that you are probably better off using the old interface for now, and keep in mind that in a year or two, you may need to update the implementation.




回答2:


I think you can implement the camera function in both sets of API and check the device`s build version first then decided to call which one implementation.

eg:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
      openCameraNewAPI();
}else{
      openCameraOldAPI();
}


来源:https://stackoverflow.com/questions/27076769/intergrate-camera-without-deprecated-methods-and-backwards-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!