$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Nova Api de Localização Android
Search
José Caique Oliveira
November 10, 2017
Programming
0
88
Nova Api de Localização Android
Slides usados no TDC Porto Alegre
José Caique Oliveira
November 10, 2017
Tweet
Share
More Decks by José Caique Oliveira
See All by José Caique Oliveira
Kotlin Flow
jcaiqueoliveira
0
120
Coroutines And Flow
jcaiqueoliveira
2
110
Testing your app
jcaiqueoliveira
0
300
Modularizando seu app
jcaiqueoliveira
0
73
Arquitetura para android
jcaiqueoliveira
6
320
Kotlin por onde começar?
jcaiqueoliveira
1
93
Introdução ao Android
jcaiqueoliveira
1
84
Arquitetura para projetos Android
jcaiqueoliveira
1
230
Kotlin 1.1
jcaiqueoliveira
0
130
Other Decks in Programming
See All in Programming
Building AI with AI
inesmontani
PRO
1
430
目的で駆動する、AI時代のアーキテクチャ設計 / purpose-driven-architecture
minodriven
11
3.7k
仕様がそのままテストになる!Javaで始める振る舞い駆動開発
ohmori_yusuke
8
4.7k
251126 TestState APIってなんだっけ?Step Functionsテストどう変わる?
east_takumi
0
280
Reactive Thinking with Signals and the new Resource API
manfredsteyer
PRO
0
140
『実践MLOps』から学ぶ DevOps for ML
nsakki55
2
490
sbt 2
xuwei_k
0
110
[堅牢.py #1] テストを書かない研究者に送る、最初にテストを書く実験コード入門 / Let's start your ML project by writing tests
shunk031
11
6.3k
スタートアップを支える技術戦略と組織づくり
pospome
8
13k
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
3
690
AIコードレビューがチームの"文脈"を 読めるようになるまで
marutaku
0
210
チーム開発の “地ならし"
konifar
8
6.4k
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.1k
Speed Design
sergeychernyshev
33
1.3k
Become a Pro
speakerdeck
PRO
30
5.6k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.2k
Typedesign – Prime Four
hannesfritz
42
2.9k
Statistics for Hackers
jakevdp
799
230k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
What's in a price? How to price your products and services
michaelherold
246
12k
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Transcript
Nova API de localização para Android Diminuindo fricção
Caique Oliveira Graduado em Ciência da computação - UFS Android
developer - Stone Apresentação
Trabalhando com localização no Android
Implementar GooglePlayServicesClient - ConnectionCallbacks - OnConnectionFailedListener
ConnectionCallbacks override fun onConnected(p0: Bundle?){ } override fun onConnectionSuspended(p0: Int){
}
OnConnectionFailedListener override fun onConnectionFailed(p0: ConnectionResult) { }
Configurar GoogleApiClient fun initGoogleApiClient() { if (mGoogleApiClient != null) {
mGoogleApiClient = GoogleApiClient.Builder( this) .addConnectionCallbacks( this) .addOnConnectionFailedListener( this) .addApi(LocationServices. API) .build() } mGoogleApiClient?.connect() }
Conectar ao Play Services override fun onStart() { mGoogleApiClient?.connect() super.onStart()
}
Desconectar de acordo com o ciclo de vida override fun
onStop() { mGoogleApiClient?.disconnect() super.onStop() }
fun getLocation(): Location { return LocationServices.FusedLocationApi .getLastLocation(mGoogleApiClient) }
Meu Deus do Céu
Todo app é a mesma coisa
“É realmente necessário que eu mesmo controle o GoogleApiClient?”
“Eu realmente preciso controlar o ciclo de vida dele?”
Android Architecture Components
Android Architecture Components - Menor escrita de código - Framework
gerencia o ciclo de vida - Traz uma melhor experiência para o desenvolvedor
Reduzindo o atrito ao trabalhar com Location
implementation ‘com.google.android.gms:play-services-location:11.6.0’
LastLocation LocationServices.getFusedLocationProviderClient(this) .lastLocation.addOnSuccessListener({ location -> Log.e("location", location.toString()) })
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." } } }
LastLocation LocationServices.getFusedLocationProviderClient(this) .lastLocation.addOnSuccessListener({ location -> Log.v("location", location.toString()) }).addOnFailureListener(this)
Location Updates LocationServices.getFusedLocationProviderClient(this) .requestLocationUpdates( locationRequest = mLocationRequest, locationCallback = mLocationCallback,
looper = Looper.myLooper())
Location Updates - Callback val mLocationCallback = object : LocationCallback()
{ override fun onLocationResult(result: LocationResult?) { super.onLocationResult(result) Log.v("location",locationResult?.lastLocation?.toString()) } }
Location Updates - Request val mLocationRequest = LocationRequest() .setInterval(UPDATE_INTERVAL_IN_MILLISECONDS) .setFastestInterval(UPDATE_INTERVAL_IN_MILLISECONDS)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
Temos agora o foco para obter de forma simples uma
localização ou resolver um problema
Obrigado! twitter: @_josecaique email:
[email protected]
slack android dev br: caique
github: jcaiqueoliveira https://goo.gl/E1QsJg
Referências https://goo.gl/dLZ8X2 https://goo.gl/itG6pa
enter.stone.com.br