title: How to solve problem with gps permissions on Android versions 12?
body: <p>GPS service is not enabled on Android versions 12 and above.
  Everything worked correctly on earlier versions</p>
  <p>I have read this <a href="https://developer.android.com/training/location/permissions" rel="nofollow noreferrer">documentation</a>,
  but I'm not sure if I have a problem with <code>android:foregroundServiceType</code> since I basically don't use it in the application.</p>
  <p>So here is some of my code AndroidManifest.xml:</p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /&gt;
  </code></pre>
  <p>And code of my vm:</p>
  <pre><code>private fun enableGps(activity: FragmentActivity) {
      val manager = activity.getSystemService(Context.LOCATION_SERVICE) as LocationManager
      if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER) &amp;&amp; hasGPSDevice(manager)) {
          locationManager.enableGps(activity)
      }
  }
  </code></pre>
  <p>And here is the implementation of the method itself:</p>
  <pre><code>override fun enableGps(activity: FragmentActivity) {
      if (googleApiClient == null) {
          googleApiClient = GoogleApiClient.Builder(context)
              .addApi(LocationServices.API)
              .addConnectionCallbacks(object : GoogleApiClient.ConnectionCallbacks {
                  override fun onConnected(bundle: Bundle?) {}
                  override fun onConnectionSuspended(i: Int) {
                      googleApiClient?.connect()
                  }
              })
              .addOnConnectionFailedListener { connectionResult -&gt;
                  Timber.e(&quot;${connectionResult.errorCode}&quot;)
              }.build()
          googleApiClient?.connect()
      }
      val locationRequest = LocationRequest.create()
      locationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY
      locationRequest.interval = 10000
      locationRequest.fastestInterval = 5000
      val builder = LocationSettingsRequest.Builder().addLocationRequest(locationRequest)
      builder.setAlwaysShow(true)
      googleApiClient?.let {
          val result: PendingResult&lt;LocationSettingsResult&gt; =
              LocationServices.SettingsApi.checkLocationSettings(it, builder.build())
          result.setResultCallback { result -&gt;
              val status: Status = result.status
              when (status.statusCode) {
                  LocationSettingsStatusCodes.RESOLUTION_REQUIRED -&gt; try {
                      // Show the dialog by calling startResolutionForResult(),
                      status.startResolutionForResult(
                          activity,
                          REQUEST_LOCATION
                      )
                  } catch (e: IntentSender.SendIntentException) {
                      Timber.e(e)
                  }
                  LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE -&gt; {
                      activity.startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))
                  }
              }
          }
      }
  }
  </code></pre>
  <p><strong>UPD</strong>
  Here is full code of my <code>DeviceLocationManager</code>, maybe I 'm requesting my <code>permissions</code> somehow wrong here:
  <a href="https://gist.github.com/mnewlive/0c0a0c1f7ccb26fe58fd6b0fa5dd1dda" rel="nofollow noreferrer">https://gist.github.com/mnewlive/0c0a0c1f7ccb26fe58fd6b0fa5dd1dda</a></p>