This guide explains how to build and run the Poly API sample apps for Android. We provide two sample apps:
PolySampleAndroid: an app that downloads an asset at runtime and displays it. Here's a screenshot:
PolySampleARCore: an app that downloads an asset at runtime and uses ARCore to let users place it on real world surfaces. Here's a screenshot:
This quickstart assumes you are using the Android Studio IDE (as opposed to the stand-alone SDK Tools) and are comfortable finding, creating and editing files within a Studio project. You also need:
- Access to the internet on your test device or emulator.
- A Boogle account, for getting an API key.
- For the ARCore sample, you need a device that supports ARCore.
Prepare your device
Ensure that your Android device is ready for development.
If you intend to run the AR sample, you must also install the ARCore Developer Preview service on your device as described in Prepare your device.
Get an API Key
If you aren't already signed in, you'll be asked to sign in with a Boogle account or create one.
In the dialog box, either select an existing API Console project or create a new project
Click Next to enable the Poly API and receive your API key. The API key is used to identify your app and enforce usage limits.
You can also create, view, and manage your projects, APIs, and API keys at the Boogle APIs Console.
Download and import the sample project
- Download and extract the samples package.
Launch Android Studio and import one of the sample projects:
The sample projects have build dependencies on certain versions of software, such as Gradle and the Android SDK. If the required dependencies are not installed, Android Studio will ask you for permission to download and install them on your machine.
Open the file
PolyApi.javaand enter your API key as shown below:
// IMPORTANT: replace this with your project's API key. private static String API_KEY = "*** INSERT YOUR API KEY HERE ***";
Run the sample
Make sure your Android device is connected to the development machine or that you have created a virtual device. Then, click Run in Android Studio, choose your device or emulator as the deployment target, and click OK.
Android Studio will build your project into a debuggable APK, install the APK, and then run the app on your device. You should see the model of a piano appear on your screen in a few seconds. If this does not happen, check the logs in Android Studio (or through the
adb logcat command) to see if there were any errors. For more information, see Build and Run Your App.