Rajubhai Rathod Rajubhai Rathod - 4 months ago 14
Java Question

ContextCompat is not applicable for the arguments

I am trying to implement permission method on one of my menu in android application but its giving me error like below

The method checkSelfPermission(Context, String) in the type ContextCompat is not applicable for the arguments (new BottomSheetListener(){}, String)


My code for this menu is like below

else if(menuItem.getItemId() == R.id.save_image) {

int gpermission = ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA);

if (gpermission != PackageManager.PERMISSION_GRANTED) {
makeRequest1();
}
else{
saveQuote();


}

}


Please check and let me know if someone can help me :)

Thanks :)

Answer

If this code is in a Activity class, write :

YourActivity.this 

instead of this, else get the context from the parent Activity and use it.