title: how to change the location mode to "high accuracy/battery saving" form it default mode(device only)
body: <p>I'm trying to implement a google map for getting current location using this tutorial</p>
  
  <p><a href="https://www.androidtutorialpoint.com/intermediate/android-map-app-showing-current-location-android/" rel="noreferrer">android google map tutorial</a></p>
  
  <p>The problem is ,It is not getting my current location untill I have started my device's google map and grant permission to access google location services.
  After this my application also get my current location. And it's working fine untill location is on in the device.
  And when location is turned off it's again need to started device's google map and grant permission for google location services.</p>
  
  <p>I have already generate the key according to instructions.</p>
  
  <p>I'm found the problem in device location mode.when I'm changing device mode to high accuracy/battery saving manually, it works fine.</p>
  
  <p><strong>So how to change the location mode to "high accuracy/battery saving" form it default mode(device only) programmatically</strong> </p>
  
  <p>Here is the Activity code:</p>
  
  <pre><code>public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,
          GoogleApiClient.ConnectionCallbacks,
          GoogleApiClient.OnConnectionFailedListener,
          LocationListener {
  
      private GoogleMap mMap;
      GoogleApiClient mGoogleApiClient;
      Location mLastLocation;
      Marker mCurrLocationMarker;
      LocationRequest mLocationRequest;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_maps);
  
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
              checkLocationPermission();
          }
          // Obtain the SupportMapFragment and get notified when the map is ready to be used.
          SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                  .findFragmentById(R.id.map);
          mapFragment.getMapAsync(this);
      }
  
  
      /**
       * Manipulates the map once available.
       * This callback is triggered when the map is ready to be used.
       * This is where we can add markers or lines, add listeners or move the camera. In this case,
       * we just add a marker near Sydney, Australia.
       * If Google Play services is not installed on the device, the user will be prompted to install
       * it inside the SupportMapFragment. This method will only be triggered once the user has
       * installed Google Play services and returned to the app.
       */
      @Override
      public void onMapReady(GoogleMap googleMap) {
          mMap = googleMap;
          mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
  
          //Initialize Google Play Services
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
              if (ContextCompat.checkSelfPermission(this,
                      Manifest.permission.ACCESS_FINE_LOCATION)
                      == PackageManager.PERMISSION_GRANTED) {
                  buildGoogleApiClient();
                  mMap.setMyLocationEnabled(true);
              }
          }
          else {
              buildGoogleApiClient();
              mMap.setMyLocationEnabled(true);
          }
      }
  
      protected synchronized void buildGoogleApiClient() {
          mGoogleApiClient = new GoogleApiClient.Builder(this)
                  .addConnectionCallbacks(this)
                  .addOnConnectionFailedListener(this)
                  .addApi(LocationServices.API)
                  .build();
          mGoogleApiClient.connect();
      }
  
      @Override
      public void onConnected(Bundle bundle) {
  
          mLocationRequest = new LocationRequest();
          mLocationRequest.setInterval(1000);
          mLocationRequest.setFastestInterval(1000);
          mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
          if (ContextCompat.checkSelfPermission(this,
                  Manifest.permission.ACCESS_FINE_LOCATION)
                  == PackageManager.PERMISSION_GRANTED) {
              LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
          }
  
      }
  
      @Override
      public void onConnectionSuspended(int i) {
  
      }
  
      @Override
      public void onLocationChanged(Location location) {
  
          mLastLocation = location;
          if (mCurrLocationMarker != null) {
              mCurrLocationMarker.remove();
          }
  
          //Place current location marker
          LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
          MarkerOptions markerOptions = new MarkerOptions();
          markerOptions.position(latLng);
          markerOptions.title("Current Position");
          markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
          mCurrLocationMarker = mMap.addMarker(markerOptions);
  
          //move map camera
          mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
          mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
  
          //stop location updates
          if (mGoogleApiClient != null) {
              LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
          }
  
      }
  
      @Override
      public void onConnectionFailed(ConnectionResult connectionResult) {
  
      }
  
      public static final int MY_PERMISSIONS_REQUEST_LOCATION = 99;
      public boolean checkLocationPermission(){
          if (ContextCompat.checkSelfPermission(this,
                  Manifest.permission.ACCESS_FINE_LOCATION)
                  != PackageManager.PERMISSION_GRANTED) {
  
              // Asking user if explanation is needed
              if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                      Manifest.permission.ACCESS_FINE_LOCATION)) {
  
                  // Show an explanation to the user *asynchronously* -- don't block
                  // this thread waiting for the user's response! After the user
                  // sees the explanation, try again to request the permission.
  
                  //Prompt the user once explanation has been shown
                  ActivityCompat.requestPermissions(this,
                          new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                          MY_PERMISSIONS_REQUEST_LOCATION);
  
  
              } else {
                  // No explanation needed, we can request the permission.
                  ActivityCompat.requestPermissions(this,
                          new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                          MY_PERMISSIONS_REQUEST_LOCATION);
              }
              return false;
          } else {
              return true;
          }
      }
  
      @Override
      public void onRequestPermissionsResult(int requestCode,
                                             String permissions[], int[] grantResults) {
          switch (requestCode) {
              case MY_PERMISSIONS_REQUEST_LOCATION: {
                  // If request is cancelled, the result arrays are empty.
                  if (grantResults.length &gt; 0
                          &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  
                      // permission was granted. Do the
                      // contacts-related task you need to do.
                      if (ContextCompat.checkSelfPermission(this,
                              Manifest.permission.ACCESS_FINE_LOCATION)
                              == PackageManager.PERMISSION_GRANTED) {
  
                          if (mGoogleApiClient == null) {
                              buildGoogleApiClient();
                          }
                          mMap.setMyLocationEnabled(true);
                      }
  
                  } else {
  
                      // Permission denied, Disable the functionality that depends on this permission.
                      Toast.makeText(this, "permission denied", Toast.LENGTH_LONG).show();
                  }
                  return;
              }
  
              // other 'case' lines to check for other permissions this app might request.
              // You can add here other case statements according to your requirement.
          }
      }
  }
  </code></pre>
  
  <p>here is the manifest file code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.googlemap"&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  
  
      &lt;permission
          android:name="com.example.envent_pc03.googlemap.permission.MAPS_RECEIVE"
          android:protectionLevel="signature" /&gt;
      &lt;uses-permission android:name="com.example.googlemap.permission.MAPS_RECEIVE"/&gt;
      &lt;uses-feature android:name="android.hardware.location.gps" /&gt;
  
      &lt;uses-feature
          android:glEsVersion="0x00020000"
          android:required="true"/&gt;
      &lt;!--
           The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
           Google Maps Android API v2, but you must specify either coarse or fine
           location permissions for the 'MyLocation' functionality. 
      --&gt;
      &lt;!--&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;--&gt;
      &lt;!--&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;--&gt;
      &lt;!--&lt;uses-permission android:name="android.permission.INTERNET" /&gt;--&gt;
      &lt;!--&lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;--&gt;
      &lt;!--
           The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
           Google Maps Android API v2, but you must specify either coarse or fine
           location permissions for the 'MyLocation' functionality.
      --&gt;
      &lt;!--&lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;--&gt;
      &lt;!--&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;--&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
  
          &lt;!--
               The API key for Google Maps-based APIs is defined as a string resource.
               (See the file "res/values/google_maps_api.xml").
               Note that the API key is linked to the encryption key used to sign the APK.
               You need a different API key for each encryption key, including the release key that is used to
               sign the APK for publishing.
               You can define the keys for the debug and release targets in src/debug/ and src/release/. 
          --&gt;
          &lt;meta-data
              android:name="com.google.android.geo.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>