Google Tango初學者教程
Getting Started with the Tango Java API
In this tutorial, we‘ll go through setting up your build environment and compiling and running your first "Hello Tango" project using the Java API, which will run sample code and display the pose data from your device.
在本教程中,我們將嘗試設置你的開發環境,使用Java API編譯並運行你的第一個“Hello Tango”工程。它將運行樣本代碼,並且展示你的設備的姿態數據。
Prerequisites提前條件
To successfully follow this guide, you will need:要成功進行該指示,你需要:
-
Android Studio
-
Experience developing Android apps. If you have never created an Android app before, you can get started with our Building Your First App tutorial.
-
The sample project. This includes the Tango Java API files, which you can find in the subfolder named TangoReleaseLibs
-
A Tango Tablet Development Kit. You can build the code without one, but you won‘t be able to run it.
Download the sample project
The sample project is hosted on GitHub. You can download it as a zip file or use git to clone the repository:
git clone https://github.com/googlesamples/tango-examples-java.git
You should now have a directory called tango-examples-java
on your machine. Within this directory you should see a subdirectory called java_basic_examples
, which contains the code for this guide.
Import the project into Android Studio
-
Do one of the following:
- Open Android Studio.
- If you are already in Android Studio with a project loaded, close the project.
Either action takes you to the Welcome to Android Studio screen.
-
Select Import Project (Eclipse ADT, Gradle, etc.). In older versions of Android Studio, this may be Import Non-Android Studio project or simply Import Project.
-
In the Select Eclipse or Gradle Project to Import dialog, navigate to the repository you just cloned. Choose the
java_basic_examples
directory and then click OK.
Connect your device
If you haven‘t already connected your Tango device to your computer, you should do so now.
Build and run an application
Within the basic examples project you loaded, you have a choice of several different "hello"-style apps to build and run. For this tutorial, we‘ll choose "Hello Motion Tracking."
-
On the toolbar, view the Run/Debug Configuration field and make sure hello_motion_tracking is the active configuration. If it is not, click the field and select it.
-
Do one of the following:
- On the Run menu, click Run.
- On the toolbar, click the Run button (the green arrow).
-
In the Device Chooser dialog, select Choose a running device, then select your Tango tablet, and then click OK.
See logcat for the raw pose data
You can see logcat output automatically in the bottom part of Android Studio.
If you want to see it in your terminal, type
adt_path/sdk/platform-tools/adb logcat
You will see the pose data being printed in your terminal:
I/MainActivity( 6010): Translation: 0.020329, 0.013915, -0.008571 | Rotation: 0.581630, 0.014597, -0.021857, 0.813029
Add to your own project
The Tango SDK for Java components are distributed on Bintray and are available through the JCenter repository when using Maven.
-
First, add
jcenter()
to yourbuild.gradle
file so Gradle can find the AARs. For example:allprojects {
repositories {
jcenter()
}
} -
Add the appropriate dependencies to the
build.gradle
files in your modules. You can determine this by looking at the samples‘build.gradle
files to see what each one needs. For example, our motion tracking sample uses:dependencies {
compile ‘com.google.tango:sdk-base:LATEST_VERSION‘
compile ‘com.google.tango:support-base:LATEST_VERSION‘
}The latest version looks like
1.51
and can be found on the downloads page. This code indicates that an application similar to the motion tracking sample needs sdk-base and support-base. This will also recursively fetch dependent libraries.
Once this is done for all of the required libraries, you will be able to reference code in the Tango SDK in your app.
If you are using your own build system, the Tango libraries are also available from the downloads page.
Next steps
Now that you have learned how to set up your environment for development with the Tango Java API, proceed to the following links to learn how to use specific features of Tango in your app:
- Configure and Connect
- Motion Tracking
- Depth Perception
- User Permissions
Also, take a look at our code samples on Github.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Google Tango初學者教程