I'm trying to use the Android camera, for API 23 or above, it requires asking for permission at runtime. According to the documentation, I can accomplish that using, ActivityCompat or ContextCompat. I don't understand what are the difference between the two and their trade-offs.
Thank you for time.
ContextCompat class is used when you would like to retrieve resources, such as drawable or color without bother about theme. It provide uniform interface to access resources and provides backward compatibility.
A helper for accessing features in Activity in a backwards compatible fashion. Construct this by using getActivityCompat(Activity) . This helper augments the included methods with data on instant apps.
To check if you have a permission, call the ContextCompat. checkSelfPermission() method. For example, this snippet shows how to check if the activity has permission to write to the calendar: int permissionCheck = ContextCompat.
I don't understand what are the difference between the two and their trade-offs
There's no trade-off really. Not sure why they wrote so - checkSelfPermission() is a method of ContextCompat
and ActivityCompat
is subclass (child) of ContextCompat
so you can pass either one whenever object of ContextCompat
class is required.
Inheritance hierarchy (docs):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With