Skip to main content

Android SDK

Add AR Clip VPS to a native Android app. The SDK finds the user's position on your VPS maps on ARCore devices, and comes with Sceneform fragments and lifecycle helpers.

Before you start​

  • Android SDK 24 (Android 7.0) or newer
  • A device with ARCore support
  • A Kotlin project (the samples are in Kotlin)
Need an API key?

Install​

  1. Make sure the project gets artifacts from Maven Central:

    allprojects {
    repositories {
    mavenCentral()
    // other repositories...
    }
    }
  2. Add the dependency to your app module:

    dependencies {
    implementation "com.arstudio:wasvps-sdk:1.0.0"
    }
  3. Sync Gradle.

Set up the manifest​

Declare the ARCore requirement. If your app's own minSdk is below 24, also add the uses-sdk override, so the build does not fail. The SDK itself still needs Android 7.0 (API 24) or newer.

<!-- Only if your app's minSdk is below 24 -->
<uses-sdk tools:overrideLibrary="com.arstudio.wasvps_sdk, com.google.ar.sceneform.sceneform, com.google.ar.sceneform.ux" />

<!-- Restrict to ARCore hardware (default). Set required=false to broaden install base. -->
<uses-feature
android:name="android.hardware.camera.ar"
android:required="true" />

To show the app to more devices in the Play Store, set android:required="false" and add tools:replace="android:required", so your value replaces the SDK's:

<uses-feature
android:name="android.hardware.camera.ar"
android:required="false"
tools:replace="android:required" />

Quick start with WASVPSArFragment​

Add the included fragment to your layout:

<!-- res/layout/activity_main.xml -->
<androidx.fragment.app.FragmentContainerView
android:id="@+id/vFragmentContainer"
android:name="com.arstudio.wasvps_sdk.ui.WASVPSArFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

supportFragmentManager.beginTransaction()
.replace(R.id.vFragmentContainer, WASVPSArFragment())
.commit()
}
}

When you have location IDs, get the service and start localization:

val fragment = supportFragmentManager
.findFragmentById(R.id.vFragmentContainer) as WASVPSArFragment

val config = WASVPSConfig.getIndoorConfig(listOf("your-location-id"))
val service = fragment.vpsService

service.setVpsConfig(config)
service.setVpsCallback(object : VpsCallback {
override fun onSuccess() = Unit
override fun onFail() = Unit
override fun onStateChange(state: State) = Unit
override fun onError(error: Throwable) {
Log.e("VPS", "Localization error", error)
}
})

service.startVpsService()

Call service.stopVpsService() when the AR experience should pause, for example in onPause.

Use your own fragment​

If you have your own ArFragment or ArSceneView, create and manage WASVPSService yourself:

class CustomArFragment : ArFragment() {
private val vpsService = WASVPSService.newInstance()

override fun onAttach(context: Context) {
super.onAttach(context)
WASVPSSdk.init(context.applicationContext)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
vpsService.bindArSceneView(arSceneView)
vpsService.setVpsConfig(WASVPSConfig.getOutdoorConfig(listOf("location-id")))
}

override fun onResume() {
super.onResume()
vpsService.resume()
vpsService.startVpsService()
}

override fun onPause() {
vpsService.pause()
vpsService.stopVpsService()
super.onPause()
}

override fun onDestroyView() {
vpsService.destroy()
super.onDestroyView()
}
}

Place content​

Add nodes as children of vpsService.worldNode. Once VPS succeeds, every child follows the localized global position.

val anchorNode = Node().apply {
setParent(vpsService.worldNode)
localPosition = Vector3(0f, 0f, -1f)
}

Troubleshooting​

  • Make sure Google Play Services for AR is installed and up to date on the test device.
  • If localization never succeeds, check the API key you give the SDK (through a secure config), and check that your location IDs exist.
  • See the /sample module in the repository for a full example, including runtime permissions and UI.