title: Permission issues for location in android Marshmallow applicaton
body: <p>I am learning to develop an android application for getting device location following Google developers forum: @<a href="http://developer.android.com/training/location/retrieve-current.html#last-known" rel="nofollow">http://developer.android.com/training/location/retrieve-current.html#last-known</a>
  @<a href="http://developer.android.com/training/location/receive-location-updates.html" rel="nofollow">http://developer.android.com/training/location/receive-location-updates.html</a></p>
  
  <p>The example shows how to use Google PLay Services for this purpose.
  But the <code>getLastLocation()</code> function always return null.</p>
  
  <blockquote>
    <p>Location location =
    LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);</p>
  </blockquote>
  
  <p>As initially the location might be null, I added the following lines to receive periodic location updates            </p>
  
  <blockquote>
    <p>LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
    mLocationRequest, this);</p>
  </blockquote>
  
  <p>which throws an Exception with the following Message</p>
  
  <blockquote>
    <p>Client must have ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION
    permission to perform any location operations</p>
  </blockquote>
  
  <p>I have already added the permissions in manifest file:</p>
  
  <blockquote>
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  </code></pre>
  </blockquote>
  
  <p>I have opened Google Maps to update current location in Google Play Service as well, but the same problem persists.
  I am newbie to Android development, and before posting this question I already searched up a lot but didn't find any solution working for me.
  I am testing it on <code>Android Marshmallow</code> device, developing using <code>Android Studio 1.3.2</code></p>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="newray.acpsa1"&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme"&gt;
          &lt;meta-data
              android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
  
          &lt;meta-data
              android:name="com.google.android.maps.v2.API_KEY"
              android:value="@string/google_maps_key" /&gt;
  
          &lt;activity
              android:name=".MapsActivity"
              android:label="@string/title_activity_maps"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>onCreate function in Activity</p>
  
  <pre><code> @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          mGoogleApiClient = new GoogleApiClient.Builder(this)
                  .addConnectionCallbacks(this)
                  .addOnConnectionFailedListener(this)
                  .addApi(LocationServices.API)
                  .build();
          mGoogleApiClient.connect();
          mLocationRequest = LocationRequest.create()
                  .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                  .setInterval(10 * 1000)        
                  .setFastestInterval(1 * 1000); 
          /* Rest functionality */
      }
  </code></pre>
  
  <p>onConnected function</p>
  
  <pre><code>@Override
      public void onConnected(Bundle bundle) {
          try{
          Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
          LatLng loc = new LatLng(21.356993, 72.826647);
          if (location == null) {
              Log.d(TAG,"location is again null");
              LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
              Log.d(TAG, "Requested for updates");
          }
          else {
              loc = new LatLng(location.getLatitude(),location.getLongitude());
              handleNewLocation(location);
          }            
          } catch (Exception e) {
              Log.d(TAG, "Error in onConnected.  "+e.getMessage());
  
          }
      }
  </code></pre>
  
  <p>Logs:</p>
  
  <pre><code>XXXX: Error in onConnected.  Client must have ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to perform any location operations.
  </code></pre>
  
  <p>dependencies in build.gradle file:</p>
  
  <pre><code>dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.android.support:appcompat-v7:23.1.0'
      compile 'com.google.android.gms:play-services:8.1.0'
      compile 'com.google.android.gms:play-services-location:8.1.0'
  }
  </code></pre>