Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Nova Api de Localização Android

Nova Api de Localização Android

Slides usados no TDC Porto Alegre

José Caique Oliveira

November 10, 2017
Tweet

More Decks by José Caique Oliveira

Other Decks in Programming

Transcript

  1. Configurar GoogleApiClient fun initGoogleApiClient() { if (mGoogleApiClient != null) {

    mGoogleApiClient = GoogleApiClient.Builder( this) .addConnectionCallbacks( this) .addOnConnectionFailedListener( this) .addApi(LocationServices. API) .build() } mGoogleApiClient?.connect() }
  2. Desconectar de acordo com o ciclo de vida override fun

    onStop() { mGoogleApiClient?.disconnect() super.onStop() }
  3. Android Architecture Components - Menor escrita de código - Framework

    gerencia o ciclo de vida - Traz uma melhor experiência para o desenvolvedor
  4. implementa OnFailureListener override fun onFailure(p0: Exception) { val statusCode =

    (p0 as ApiException).statusCode when (statusCode) { RESOLUTION_REQUIRED -> { //Fix in Settings." } SETTINGS_CHANGE_UNAVAILABLE -> { //Fix in Settings." } } }
  5. Location Updates - Callback val mLocationCallback = object : LocationCallback()

    { override fun onLocationResult(result: LocationResult?) { super.onLocationResult(result) Log.v("location",locationResult?.lastLocation?.toString()) } }
  6. Temos agora o foco para obter de forma simples uma

    localização ou resolver um problema