Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Geofencing avec Google Places
Search
Robin Caroff
January 24, 2017
Programming
0
38
Geofencing avec Google Places
Présentation du Geofencing sur Android avec Google Places.
Robin Caroff
January 24, 2017
Tweet
Share
More Decks by Robin Caroff
See All by Robin Caroff
Migration Android 14
robincaroff
1
77
À la découverte du développement mobile (sans les maux de tête)
robincaroff
0
41
À la découverte du développement mobile (sans les maux de tête) - SHORT
robincaroff
0
73
Rex - Migration Android 13
robincaroff
0
38
App-Elles - Exemple de tech for good mobile à l'heure du confinement
robincaroff
0
100
From Dagger to Dagger Hilt
robincaroff
0
220
Android Async Talk
robincaroff
1
110
Feedback: How I brought Kotlin into my Room (short)
robincaroff
0
69
Other Decks in Programming
See All in Programming
Netty Chicago Java User Group 2024-04-17
sullis
0
180
障害対応を起点としたもっといい開発と運用のサイクル作りのためにできること / Hatena Enginner Seminar #29
polamjag
0
180
使ってみよう Azure AI Document Intelligence
kosmosebi
2
320
GitHub Actionsで泣かないためにやっておきたい設定 / Recommended GHA settings to avoid crying
pinkumohikan
3
530
0→1と1→10の狭間で Javaという技術選定を振り返る/Reflecting on the Decision to Choose Java Between Scaling from 0 to 1 and 1 to 10
jaguar_imo
2
380
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
960
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
1
1k
Site Reliability Engineering for GMO
pyama86
8
1k
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
270
Fast JSX: Don't clone props object #28768
yossydev
1
110
SIMD Parallel Programming with the Vector API
josepaumard
0
180
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
270
Featured
See All Featured
Teambox: Starting and Learning
jrom
128
8.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
14
1.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
187
16k
StorybookのUI Testing Handbookを読んだ
zakiyama
13
4.6k
Automating Front-end Workflow
addyosmani
1356
200k
Git: the NoSQL Database
bkeepers
PRO
422
63k
Fantastic passwords and where to find them - at NoRuKo
philnash
37
2.5k
Agile that works and the tools we love
rasmusluckow
325
20k
Faster Mobile Websites
deanohume
299
30k
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.9k
Building an army of robots
kneath
300
41k
Transcript
GEOFENCING AVEC GOOGLE PLACES ANDROID NANTES - JANVIER 2017 Par
@RobinCaroff
LE PROBLÈME
GEOFENCING https://developer.android.com
GEOFENCING https://developers.google.com
GEOFENCING Dépendances Gradle dependencies { compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.google.android.gms:play-services:9.4.0' }a
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1' a
compile 'com.google.android.gms:play-services-location:9.4.0' }a GEOFENCING Dépendances Gradle
GEOFENCING dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1'
a compile 'com.google.android.gms:play-services-location:9.4.0' compile 'com.google.android.gms:play-services-maps:9.4.0' compile 'com.google.android.gms:play-services-places:9.4.0' }a Dépendances Gradle
PERMISSIONS <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.robincaroff.mygeofencer" > <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application> ... </application> </manifest> Manifest
PERMISSIONS <application android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/maps_apikey"/> ... <service
android:name=".services.GeofenceTransitionsIntentService"/> </application> Manifest
PERMISSIONS <application android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/maps_apikey"/> ... <service
android:name=".services.GeofenceTransitionsIntentService"/> </application> Manifest pour Place Picker
PERMISSIONS La technique
PERMISSIONS La technique du
PERMISSIONS La technique du SPLASH SCREEN
PERMISSIONS @Override protected void onCreate(Bundle savedInstanceState) { ... checkPermissions(); }a
private void checkPermissions() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION); } else { goToMainActivity(); }b }c
PERMISSIONS @Override protected void onCreate(Bundle savedInstanceState) { ... checkPermissions(); }a
private void checkPermissions() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION); } else { goToMainActivity(); }b }c
GOOGLE API CLIENT protected synchronized void buildGoogleApiClient() { mGoogleApiClient =
new GoogleApiClient .Builder(context) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .addApi(Places.GEO_DATA_API) .addApi(Places.PLACE_DETECTION_API) .build(); }
GOOGLE API CLIENT @Override protected void onStart() { super.onStart(); mGoogleApiClient.connect();
} @Override protected void onStop() { super.onStop(); mGoogleApiClient.disconnect(); }
GEOFENCES https://developer.android.com
CREATE A GEOFENCE Geofence geofence = new Geofence.Builder() .setRequestId(STRING_ID) .setCircularRegion(
LATITUDE, LONGITUDE, RADIUS_IN_METERS ) .setExpirationDuration(EXPIRATION_IN_MILLISECONDS) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) .build());
CREATE A GEOFENCE Geofence geofence = new Geofence.Builder() .setRequestId(STRING_ID) .setCircularRegion(
LATITUDE, LONGITUDE, RADIUS_IN_METERS ) .setExpirationDuration(EXPIRATION_IN_MILLISECONDS) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) .build());
CREATE A GEOFENCE Geofence geofence = new Geofence.Builder() .setRequestId(STRING_ID) .setCircularRegion(
LATITUDE, LONGITUDE, RADIUS_IN_METERS ) .setExpirationDuration(EXPIRATION_IN_MILLISECONDS) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) .build());
CREATE A GEOFENCE Geofence geofence = new Geofence.Builder() .setRequestId(STRING_ID) .setCircularRegion(
LATITUDE, LONGITUDE, RADIUS_IN_METERS ) .setExpirationDuration(EXPIRATION_IN_MILLISECONDS) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) .build());
GEOFENCING REQUEST private GeofencingRequest getGeofencingRequest() { GeofencingRequest.Builder builder = new
GeofencingRequest.Builder(); builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER); builder.addGeofences(mGeofenceList); return builder.build(); }
GEOFENCE INTENT private PendingIntent getGeofencePendingIntent() { if (mGeofencePendingIntent != null)
{ return mGeofencePendingIntent; } Intent intent = new Intent(this, GeofenceTransitionsIntentService.class); return PendingIntent.getService(this, 0, intent, PendingIntent. FLAG_UPDATE_CURRENT); }
START / STOP GEOFENCING LocationServices.GeofencingApi.addGeofences( mGoogleApiClient, getGeofencingRequest(), getGeofencePendingIntent() ).setResultCallback(this); LocationServices.GeofencingApi.removeGeofences(
mGoogleApiClient, getGeofencePendingIntent() ).setResultCallback(this);
START / STOP GEOFENCING LocationServices.GeofencingApi.addGeofences( mGoogleApiClient, getGeofencingRequest(), getGeofencePendingIntent() ).setResultCallback(this); LocationServices.GeofencingApi.removeGeofences(
mGoogleApiClient, getGeofencePendingIntent() ).setResultCallback(this);
None
NOT BORING AT ALL…
SHOW ME HOW IT WORKS !
TESTS ▸ Real testing ▸ Mock location apps ▸ Emulator
▸ Mock location provider
LIMITATIONS
LIMITATIONS 100 geofences par application et par utilisateur (pour un
device)
BEST PRACTICES ▸ Réduire l’utilisation de la batterie en changeant
la ‘réactivité’ des notifications ▸ Optimiser les rayons de geofences ▸ Surveiller seulement quand c’est nécessaire ▸ Utiliser les transitions DWELL plutôt que ENTER