android - ActivityCompat 和 ContextCompat 有什么区别?

标签 android android-camera android-camera-intent android-camera2

我正在尝试使用 Android 相机,对于 API 23 或更高版本,它需要在运行时请求许可。根据documentation ,我可以使用 ActivityCompat 或 ContextCompat 来完成。我不明白两者之间有什么区别以及它们的取舍。

感谢您的宝贵时间。

最佳答案

I don't understand what are the difference between the two and their trade-offs

真的没有取舍。不知道他们为什么这么写 - checkSelfPermission()ContextCompat 的方法和 ActivityCompatContextCompat 的子类(子类)所以你可以在任何时候传递 ContextCompat 的对象类是必需的。

继承层次结构(docs):

enter image description here

关于android - ActivityCompat 和 ContextCompat 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38229842/

相关文章:

android - 通过我的应用程序使用 Intent 打开相机时停止保存图像

Android LinearLayout 分隔线,但百分比?

java - ProGuard 中类路径前的感叹号有什么作用?

android - 强制 Android 中的相机提供 30 FPS

android - 三星 Galaxy 设备相机 Intent 问题

Android ACTION_IMAGE_CAPTURE Intent

android - 在 Android Studio 中更改 Github 帐户

android - 在 Android 中绘制对象的纹理?

android - 在 Zxing 条码应用程序中出现相机错误

android - Samsung Galaxy SIII 问题 - Camera.onPictureTaken() 返回交错图像而不是正确的捕获图像