title: FusedLocation not trigger locationcallback for android api <= 21
body: <p>so I want to get the latitude and longitude from the device, but when I build my application on android Lollipop or API 22 I'm not getting the current latitude and longitude. is this because of android permission or what? here is my code</p>
  <p>I'm using play service location version:</p>
  <p>implementation 'com.google.android.gms:play-services-location:17.0.0'</p>
  <p><strong>LocationUser.kt</strong></p>
  <pre><code>class LocationUser(context: Context) {
      private var fusedLocation: FusedLocationProviderClient? = null
      private val INTERVAL: Long = 300000
      private val FASTEST_INTERVAL: Long = 300000
      private val REQUEST_LOCATION_PERMISSION = 1
      lateinit var locationRequest: LocationRequest
      private lateinit var lastLocation: Location
  
  
      fun startLocationUpdates(context: Context) {
          Log.d(&quot;LOCATION UPDATE&quot;, &quot;started location update&quot;)
          locationRequest = LocationRequest()
          locationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY
          locationRequest.interval = INTERVAL
          locationRequest.fastestInterval = FASTEST_INTERVAL
  
          val builder = LocationSettingsRequest.Builder()
          builder.addLocationRequest(locationRequest)
          val locationSettingsRequest = builder.build()
  
          val settingsClient = LocationServices.getSettingsClient(context)
          settingsClient.checkLocationSettings(locationSettingsRequest)
  
          fusedLocation = LocationServices.getFusedLocationProviderClient(context)
          if (ActivityCompat.checkSelfPermission(
                  context,
                  android.Manifest.permission.ACCESS_FINE_LOCATION
              ) != PackageManager.PERMISSION_GRANTED &amp;&amp;
              ActivityCompat.checkSelfPermission(
                  context,
                  android.Manifest.permission.ACCESS_COARSE_LOCATION
              ) != PackageManager.PERMISSION_GRANTED
          ) {
              return
          }
          fusedLocation!!.requestLocationUpdates(locationRequest, locationCallback, Looper.myLooper())
          Log.d(&quot;LOCATION UPDATE&quot;, &quot;end location update&quot;)
      }
  
      fun isPermissionGranted(context: Context): Boolean {
          return if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
              if (context.checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) ==
                  PackageManager.PERMISSION_GRANTED
              ) {
                  true
              } else {
                  ActivityCompat.requestPermissions(
                      context as Activity, arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION),
                      REQUEST_LOCATION_PERMISSION
                  )
                  false
              }
          } else {
              true
          }
      }
  
      private val locationCallback = object : LocationCallback() {
          override fun onLocationResult(locationResult: LocationResult) {
              locationResult.lastLocation
              onLocationChanged(context, locationResult.lastLocation)
              super.onLocationResult(locationResult)
          }
      }
  
      fun onLocationChanged(context: Context, location: Location) {
          Log.d(&quot;UWUWU&quot;, &quot;location changed&quot;)
          lastLocation = location
          val geocoder = Geocoder(context, Locale.getDefault())
          val latitude = lastLocation.latitude
          val longitude = lastLocation.longitude
          val sharedPref = SharedPref(context)
          Log.d(&quot;latitude&quot;, latitude.toString())
          Log.d(&quot;longitude&quot;, longitude.toString())
          sharedPref.saveStringPref(&quot;latitude_user&quot;, latitude.toString())
          sharedPref.saveStringPref(&quot;longitude_user&quot;, longitude.toString())
  
          try {
              val addresses: List&lt;Address&gt; = geocoder.getFromLocation(latitude, longitude, 1)
              val namaKota = addresses[0].subAdminArea
              val namaKecamatan = addresses[0].locality
              sharedPref.saveStringPref(&quot;alamat_user&quot;, &quot;$namaKecamatan, $namaKota&quot;)
          } catch (e: Exception) {
              e.localizedMessage
          }
          Log.d(&quot;UWUWU&quot;, &quot;location changed&quot;)
  
      }
  }
  </code></pre>
  <p>and in the activity I called the class like this</p>
  <p><strong>MainActivity.kt</strong></p>
  <pre><code>class MainActivity : AppCompatActivity() {
  
      private val REQUEST_LOCATION_PERMISSION = 1
      private val REQUESTING_LOCATION_UPDATES_KEY = &quot;requesting_location_update&quot;
      private val  requestingLocationUpdates = true
      val locationUser = LocationUser(this)
  
      @SuppressLint(&quot;SimpleDateFormat&quot;, &quot;SetTextI18n&quot;)
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          ../
          val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
          if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
              checkUserGPS()
          }
  
          if(locationUser.isPermissionGranted(this)){
              locationUser.startLocationUpdates(this)
          }
          Log.d(&quot;GRANTED ?&quot;, locationUser.isPermissionGranted(this).toString())
      }
  
      override fun onCreateOptionsMenu(menu: Menu?): Boolean {
          menuInflater.inflate(R.menu.menu_setting, menu)
          return true
      }
  
      override fun onOptionsItemSelected(item: MenuItem): Boolean {
          if (item.itemId == R.id.menu_settings) {
              val intent = Intent(this, SettingsActivity::class.java)
              startActivity(intent)
              return true
          }
          return super.onOptionsItemSelected(item)
      }
  
  
      override fun onRequestPermissionsResult(
          requestCode: Int,
          permissions: Array&lt;out String&gt;,
          grantResults: IntArray
      ) {
          if (requestCode == REQUEST_LOCATION_PERMISSION) {
              if (grantResults.contains(PackageManager.PERMISSION_GRANTED)) {
                  Toast.makeText(this, &quot;permission granted&quot;, Toast.LENGTH_SHORT).show()
              }
          }
      }
  
      private fun checkUserGPS() {
          val dialog = AlertDialog.Builder(this)
          dialog.setMessage(&quot;GPS tidak aktif, apakah kamu ingin megaktifkannya?&quot;)
              .setCancelable(false)
              .setPositiveButton(&quot;iya&quot;) { _, which -&gt;
                  startActivityForResult(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 11)
              }
              .setNegativeButton(&quot;tidak&quot;) { dialog, _ -&gt;
                  dialog.cancel()
                  finish()
              }
              .create()
              .show()
      }
  
      override fun onResume() {
          locationUser.startLocationUpdates(this)
          super.onResume()
      }
  
  }
  </code></pre>
  <p>when I see log I noticed that the function of onLocationChange not called when function startLocationUpdates function is called. is this because of permission or what, I'm suffering StackOverflow and get this question which is vice versa with my problem, and I noticed the same thing which is locationcallback is not triggered</p>
  <p><a href="https://stackoverflow.com/questions/52961114/fusedlocationproviderclient-requestlocationupdates-doesnt-trigger-locationcallb">FusedLocationProviderClient requestLocationUpdates doesn&#39;t trigger LocationCallBack for API 23 above</a></p>
  <p>I'm confused right now</p>