title: checkSelfPermission nullpointer 6.0
body: <p>I have a problem with a check permisions always says nullpointer my debug in 6.0: </p>
  
  <p>what am I doing wrong</p>
  
  <pre><code>public String getGeolocation(Context context){
  
      try{        
          int MY_PERMISSION_ACCESS_COURSE_LOCATION = 1000;         
  
          if ( ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED ) {
  
              ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION},
                      MY_PERMISSION_ACCESS_COURSE_LOCATION);
          }
          if ( Build.VERSION.SDK_INT &gt;= 23 &amp;&amp;
                  ContextCompat.checkSelfPermission( context, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED &amp;&amp;
                  ContextCompat.checkSelfPermission( context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
              //return 0 ;
          }
          mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Here is nullpointer
          //Location location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
          Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
          if(location != null &amp;&amp; location.getTime() &gt; Calendar.getInstance().getTimeInMillis() - 2 * 60 * 1000) {
              // Do something with the recent location fix
              //  otherwise wait for the update below
          }
          else {
              //mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
              mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,  0, 0, this);
          }
      }catch (Exception e){}
  return geo;
  
  }
  </code></pre>
  
  <p>// I use this method to get data : </p>
  
  <pre><code>public void onLocationChanged(Location location) {
      if (location != null) {
          Log.v("Location Changed", location.getLatitude() + " and " + location.getLongitude());
          geo = ""+location.getLatitude() + " , " + location.getLongitude();
          mLocationManager.removeUpdates(this);
      }
  }
  </code></pre>
  
  <p>Error exception from Android studio : </p>
  
  <pre><code>java.lang.IllegalStateException: System services not available to Activities before onCreate()
  </code></pre>
  
  <p>Where I call getGeolocation() ? </p>
  
  <pre><code>public class AlarmReceiverCustom extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
  getGeolocation(context)
  </code></pre>