-1

I have a question and I want to hear an answer for this cause I really search it for a long time and it really doesn't matter what I'm doing I still get the error. Here is the code that I wrote :

if (getContext() != null) {
   if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {}

Before I try to load the Map I'm checking the permission for he Locations so inside onMapLoaded I'm checking like above.

Is there any tricks or is this a bug in ContextCompat ?

Error:

Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference

Olcay Sönmez
  • 602
  • 1
  • 7
  • 16

1 Answers1

0

You can do like this also

if ((ActivityCompat.checkSelfPermission(SplashActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
                ActivityCompat.requestPermissions(SplashActivity.this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 100);
}
Saurabh Vadhva
  • 511
  • 5
  • 12