我正在尝试使用 Android 相机,对于 API 23 或更高版本,它需要在运行时请求许可。根据documentation ,我可以使用 ActivityCompat 或 ContextCompat 来完成。我不明白两者之间有什么区别以及它们的取舍。
感谢您的宝贵时间。
最佳答案
I don't understand what are the difference between the two and their trade-offs
真的没有取舍。不知道他们为什么这么写 - checkSelfPermission()是 ContextCompat
的方法和 ActivityCompat
是 ContextCompat
的子类(子类)所以你可以在任何时候传递 ContextCompat
的对象类是必需的。
继承层次结构(docs):
关于android - ActivityCompat 和 ContextCompat 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38229842/