代码A来自CameraX项目,您可以看到源代码。
当我删除@SuppressLint("RestrictedApi")时,Android将显示“只从同一个库组调用”,您可以看到图像1。
为什么我不能删除代码A中的@SuppressLint("RestrictedApi")?限制API意味着什么?
码A
@SuppressLint("RestrictedApi")
private fun updateCameraUi() {
...
// Listener for button used to switch cameras
controls.findViewById<ImageButton>(R.id.camera_switch_button).setOnClickListener {
lensFacing = if (CameraX.LensFacing.FRONT == lensFacing) {
CameraX.LensFacing.BACK
} else {
CameraX.LensFacing.FRONT
}
try {
// Only bind use cases if we can query a camera with this orientation
CameraX.getCameraWithLensFacing(lensFacing)
// Unbind all use cases and bind them again with the new lens facing configuration
CameraX.unbindAll()
bindCameraUseCases()
} catch (exc: Exception) {
// Do nothing
}
}
}图像1

发布于 2020-03-05 14:32:46
自本教程编写以来,库中发生了一些重大变化。
将包版本恢复到1.0.0-alpha06,与教程一样,解决了这个问题。
发布于 2020-03-02 13:47:37
这些问题与库不影响您的代码。
在使用这些API的几个代码示例中,文件中经常有一个@SuppressLint("RestrictedApi")隐藏警告。
尽管您必须确保使用的是正确的依赖版本,但项目仍然应该按其应有的方式编译和运行。API的变化非常频繁,如果您引用的是一个示例,那么它可能使用的是一个已经更改的旧版本。
最好的方法是直接查看源代码,如果您正在调用的方法声明为public,那么您可能不会有问题。
https://stackoverflow.com/questions/58567716
复制相似问题