Prerequisites
Before starting this tutorial, you need the following:
-
An ArcGIS Location Platform or ArcGIS Online account.
-
A development and deployment environment that meets the system requirements.
-
An IDE for Android development in Kotlin.
Steps
You need an access token to use the location services used in this tutorial.
-
Go to the Create an API key tutorial to obtain a new API key access token.
-
Ensure that the following privilege is enabled: Location services > Basemaps > Basemap styles service.
-
Copy the access token as it will be used in the next step.
-
-
In Android Studio, click the Android view in your app project. Then open app -> kotlin+java -> com.example.app -> MainActivity.kt.
- In
Main
, addActivity.kt ArcGISEnvironment
andApiKey
to your imports.
MainActivity.ktUse dark colors for code blocks package com.example.app import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import com.arcgismaps.ApiKey import com.arcgismaps.ArcGISEnvironment import com.example.app.screens.MainScreen import com.example.app.ui.theme.TutorialTheme
- Set the
ArcGISEnvironment.apiKey
property by callingApiKey.create()
and passing your API Key access token.
MainActivity.ktUse dark colors for code blocks class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ArcGISEnvironment.apiKey = ApiKey.create("YOUR_ACCESS_TOKEN") enableEdgeToEdge() setContent { TutorialTheme { MainScreen() } } } }
- In
For more information, see API key authentication.
Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.