ArcGIS Runtime SDK for Android: Building Apps Shelly Gill
Agenda
•
Getting started
•
API
•
•
-
Android Runtime SDK patterns
-
Common functions, workflows
The Android platform
Other sessions covered Runtime SDK generally: An Introduction to the API and Architecture, Building 3D Applications, Working with Maps Online and Offline
Getting started With a tutorial, gradle, or samples
Getting started with the SDK
Sign up for free Developers testing account
1. -
50 credits a month, premium content, register apps, test tokens
Install free Android Studio IDE
2. -
http://developer.android.com/sdk
Get dependencies automatically with Gradle and try it out
3. -
Write an app!
New developers - Follow first map app tutorial
•
Developers site > Android > Guide -
http://developers.arcgis.com/android/latest/guide
-
Help topics
•
Getting started > Develop your first map app
•
Step-by-step guide
•
Or try Dev Labs -
8 so far
-
https://developers.arcgis.com/labs/develop/index.html#android
Existing developers - clone samples or example apps
•
GitHub -
•
https://github.com/Esri
API samples -
Java, and adding Kotlin
-
http://github.com/Esri/arcgis-runtime-samples-android
•
Example apps
•
Clone/checkout/download, import, and run
Existing apps - add AAR dependency
•
Maven repository hosted by Bintray -
•
AARs of current and previous releases
Project build.gradle repositories { maven {
url 'https://esri.bintray.com/arcgis' } •
App module build.gradle dependencies { compile 'com.esri.arcgisruntime:arcgis-android:100.1.0' }
SDK resources
•
Developers site -
http://developers.arcgis.com/android
-
Doc – guide, API Reference
-
Downloadable SDK
-
Application support
•
GitHub for samples and example apps
•
GeoNet user communities -
http://geonet.esri.com/community/developers/native-app-developers/arcgis-runtime-sdk-forandroid
-
https://community.esri.com/groups/arcgis-example-apps
Example apps
•
Real world apps based on use cases collected from users
•
Complete working apps with detailed instructions for getting started
•
Supporting documentation -
code, data creation, app workflows, customization
•
Open sourced on GitHub (Apache 2.0 license)
•
Current Android apps: -
•
Maps App, Ecological Marine Units, Nearby Places, Offline Mapbook
Future apps: -
Mobile data collection, Situational awareness
-
Vote at https://community.esri.com/polls/2636
Functionality •
Build apps for Android devices
•
Visualize geographic data – maps, scenes, layers, graphics -
feature, dynamic, tiled, raster, …
•
Identify features, query data, and display info pop-ups
•
Share maps and content across ArcGIS platform
•
Offline maps, data, routing, geocoding
•
Powerful analysis and local geometric operations
https://developers.arcgis.com/android/latest/guide/essential-vocabulary.htm
API
ListenableFuture pattern
•
•
Asynchronous methods use ListenableFuture -
Inherits from java Future interface
-
A promise to return a result
-
Add done listener, or call get (blocking)
Can simplify asynchronous programming -
Done called back on UI thread if listener added on UI thread
-
We take care of executing operations on background threads
-
Standard pattern for cancellation, errors
ListenableFuture Sample – identify-graphics-hittest
// Get future ListenableFuture = mMapView.setViewpointAsync(firstViewpoint, 3); // Add done listener booleanListenableFuture.addDoneListener(new Runnable() { @Override public void run() { try { // get result of the future if (MainActivity.this.booleanListenableFuture.get()) { // Proceed with more… mMapView.setViewpointAsync(secondViewpoint, 3); } } catch (InterruptedException ie) {
// user interrupted the operation
} catch (ExecutionException ee) { } });
}
// a problem with executing the call or returning result
ListenableList pattern
•
Bind to data
•
Add listener to know when content changes -
•
Adds and removes
Implemented on -
Graphics in a GraphicsOverlay
-
LayerList (operational, base, reference layers)
-
Sublayers in SublayerList
-
Bookmarks
Loadable pattern – Java implementation
•
Loadable resources -
•
•
Maps, layers, portal item, geodatabase, …
Does not use ListenableFuture -
Specific pattern for load errors
-
Has additional states
-
Can reload if failed
Loads dependent loadables
•
https://developers.arcgis.com/android/latest/guide/loadable-pattern.htm
Map and MapView
•
Content and presentation are separated
•
ArcGISMap - separate class that defines content Listenable lists of Layer, Bookmark - MapView references ArcGISMap -
-
•
Open a map, or build in code, modify, save to portal
MapView extends android.view.ViewGroup -
GraphicsOverlay(s), LocationDisplay, …
-
Control visible extent of ArcGISMap using Viewpoints
Don't forget andoid.permission.INTERNET for any online layers, basemaps, portals, etc
Scene and SceneView
•
New in Android at v100.1
•
ArcGISScene – content
•
-
SceneView references ArcGISScene
-
Basemap, ElevationSurface, Layers, …
-
Build in code
SceneView extends android.view.ViewGroup -
•
Control view using Viewpoints and Cameras
Currently requires OpenGL2.0 -
Covers all devices connecting to Google Play
Scene and layer Code Display a scene Add elevation surface Add a scene layer
// create a scene and add a basemap to it
ArcGISScene scene = new ArcGISScene(); scene.setBasemap(Basemap.createImagery()); mSceneView = findViewById(R.id.sceneView); mSceneView.setScene(scene);
// create an elevation source, and add this to the base surface of the scene
ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(getResources().getString(R.string.elevation_source)); scene.getBaseSurface().getElevationSources().add(elevationSource);
// add a scene service to the scene for viewing buildings ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer( getResources().getString(R.string.buildings_service)); scene.getOperationalLayers().add(sceneLayer);
// add a camera and initial camera position
Camera camera = new Camera(48.378, -4.494, 200, 345, 65, 0); mSceneView.setViewpointCamera(camera);
Display device location •
Uses Android platform location providers -
GPS and network location, if enabled
•
Customizable appearance
•
AutoPan behavior – pan, rotate
•
-
Navigation (car)
-
CompassNavigation (waypoint)
-
Recenter (no rotation)
LocationDisplay -
MapView.getLocationDisplay()
-
LocationDisplay.startAsync()
Only Position
Position & Heading
Position & Course
LocationDisplay top tips
•
•
•
Don’t forget -
android.permission.ACCESS_COARSE_LOCATION +
-
android.permission.ACCESS_FINE_LOCATION
User interactive navigation cancels auto-pan -
MapView.addNavigationChangedListener – when isNavigating returns to false, re-set the AutoPanMode
-
Or disable interactive navigation…
User interactive navigation can also change scale -
•
Again can use addNavigationChangedListener and re-set map scale if required
Can create own LocationDataSource if required
Handling touch on the map
•
•
Default navigation gestures -
Swipe to pan
-
Double-tap = zoom in, two-finger-tap = zoom out
-
Pinch to zoom and rotate
-
Tap and hold then swipe up/down for continuous zoom
Change interactive navigation by creating custom touch listener -
Inherit from DefaultMapViewOnTouchListener
-
Implement View.OnTouchListener
Handling gestures Sample – identify-graphics-hittest
Integration with the ArcGIS Platform using Portal API
•
•
Portal -
Connection to ArcGIS Online or an on-premises Portal
-
Authenticated and anonymous access
PortalUser -
•
Current authenticated user or other users
PortalItem -
Represent any item type
-
Create, update, delete items and PortalFolders
-
Share publicly, organization, or PortalGroup
MobileMapPackage
•
Provide offline maps so users can be productive when network connectivity is poor or nonexistent
•
MobileMapPackage class -
•
Desktop pattern -
•
maps, layers, data, locators, transportation networks Create MMPK in Pro
Services pattern -
Use OfflineMapTask
ArcGIS Runtime SDKs: Working with Maps Online and Offline 2pm - B 07 - B 08
Offline Mapbook Example App Offline Mapbook Example App
Authentication – default challenge handler
•
Cross-platform security pattern -
•
•
Challenges, challenge handlers, OAuth2, tokens
DefaultAuthenticationChallengeHandler -
Out of the box UX for challenges
-
Network credential: HTTP secured service / Integrated Windows Authentication (IWA).
-
ArcGIS Tokens: proprietary token-based authentication
-
PKI certificates
-
Self signed certificates
Create own handler if required -
Implement AuthenticationChallengeHandler
Security pattern – OAuth 2.0
•
Used by ArcGIS Online
•
OAuthConfiguration
•
-
Provides challenge handling specifically for OAuth
-
Uses default Android browser app to display login UX
Set this up -
Create Application - Developers site account
-
Set DefaultAuthenticationChallengeHandler
-
Create OAuthConfiguration
Authentication code Maps App example app: • AuthenticationManager • DefaultAuthenticationChallengeHandler • OAuthConfiguration
Android Platform
Android Platform
Android platforms: connections to Google Play store 2nd Oct 2017
Runtime SDK supports minimum Android API 16 (“Jelly Bean” Android 4.1) defaultConfig { minSdkVersion 16 }
Nougat + Oreo
•
No need for separate JDK
Lollipop
•
What about your deployments?
•
-
API 16 (Jelly Bean)?
-
API 19 (Kit Kat)?
-
API 24 Nougat or forward
Marshmallow
KitKat Jelly Bean Older
Android Studio 3
•
Significant update to Android Studio -
IDE - Parameter hints, semantic highlighting
-
Tooling – Debugging, Instant Apps templates, Android Profiler, new gradle plugin + optimizations
•
Release Candidate 2 – Oct 19th Final released last night!
•
Java 8 language features as standard
•
Migrate projects forward from 2.3.3 release
•
Supports Kotlin
Kotlin
•
•
•
New official language -
Interoperable with Java, Java standard types
-
Open source, by JetBrains - http://kotlinlang.org/docs/reference/
Modern language features -
Null safety/nullable types, default parameter values
-
Lambdas, inferred properties, higher order functions + function types, auto-casting
Support in Runtime SDK -
Migrating samples
-
Future plans for documentation
-
Example apps -
ask at https://community.esri.com/groups/arcgis-exampleapps/content?filterID=contentstatus%5Bpublished%5D~objecttype~objecttype%5Bthread%5D
In conclusion
•
Free to get going -
Android Studio
-
Free Developers account for testing
-
ArcGIS Runtime SDK for Android
•
Runtime SDK support for wide range of functionality and workflows
•
GeoNet – questions, discussions, suggestions
•
Feedback in the conference app
Thank You to Our Generous Sponsor