title: CheckPermissions Error for LocationManager in Android Studio
body: <p>I had a good working app for GetGeoLocation for API level 23( Using checkSelfPermission). But, then i had to make it compatible with API level 21. So, checkSelfPermission didn't work as it was introduced in API Level 23.</p>
  
  <p>So, i changed the code to accomodate this:</p>
  
  <pre><code> protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      CheckForCoarseLocationPermission();
  
  }
  private void CheckForCoarseLocationPermission()
  {
      if (android.os.Build.VERSION.SDK_INT &gt;= 23)
      {
          // ANDROID 6.0 AND UP!
          boolean accessCoarseLocationAllowed = false;
          try
          {
              // Invoke checkSelfPermission method from Android 6 (API 23 and UP)
              java.lang.reflect.Method methodCheckPermission = Activity.class.getMethod("checkSelfPermission", java.lang.String.class);
              Object resultObj = methodCheckPermission.invoke(this, Manifest.permission.ACCESS_COARSE_LOCATION);
              int result = Integer.parseInt(resultObj.toString());
              if (result == PackageManager.PERMISSION_GRANTED)
              {
                  accessCoarseLocationAllowed = true;
  
  
              }
          }
          catch (Exception ex)
          {
          }
          if (accessCoarseLocationAllowed)
          {
              Log.v("TAG","Granted");
              LocationManager locationManager=    (LocationManager)getSystemService(Context.LOCATION_SERVICE);
                  locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,new LocationListener());//ERROR Happening Here!!!!!!!!!!!
          }
          try
          {
              // We have to invoke the method "void requestPermissions (Activity activity, String[] permissions, int requestCode) "
              // from android 6
              java.lang.reflect.Method methodRequestPermission = Activity.class.getMethod("requestPermissions", java.lang.String[].class, int.class);
              methodRequestPermission.invoke(this, new String[]
                      {
                              Manifest.permission.ACCESS_FINE_LOCATION
                      }, 0x12345);
          }
          catch (Exception ex)
          {
          }
      }
  }
  </code></pre>
  
  <p>Now, the LocationManager.requestLocationUpdate is giving an error
  <strong>Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with <code>checkPermission</code>) or explicitly handle a potential <code>SecurityException</code> less</strong></p>
  
  <p>How to tackle it, if i want to use LocationManager and CheckPermission for API level >=21.</p>
  
  <p>Kindly, help. </p>