[JAVA] Until the Google Assistant sample runs on Android Things

Introduction

This article is a memorandum when I tried running Android Things on Raspberry Pi3 Model B. I am running in an environment where Android Studio 2.2 or higher and ADB commands can be used.

Things necessary

Writing image

Download the latest image from the Official Page and unzip it. Since it is about 4GB, it will take some time to deploy. Connect the MicroSD card to your PC using a card reader or the like. It seems that it may not be recognized by the slot attached to the notebook PC etc. In that case, please purchase a card reader. Follow the steps here (https://www.raspberrypi.org/documentation/installation/installing-images/windows.md) to install Win32DiskImager and write the image.

Switch and LED settings

Assemble the circuit while looking at the image in the README of sample-button. However, since the Assistant sample does not move at this rate, change the LED wire (blue line in the image) to BCM25 (11th from the upper right) and change the switch wire (green line in the image) to BCM23 (from the upper right). Please change to 8th).

Connect

Attach the SD card, HDMI cable, LAN cable, USB microphone, and speaker to the Raspberry Pi. Check the switch and LED circuits again and turn on the power. If the Android Things startup screen appears, it is successful. Since the IP address is displayed on the screen, try connecting from a PC on the same network. Start a command prompt and enter the following code. > adb connect [IP address] When a message such as Success appears, the connection is complete.

WiFi settings for Raspberry Pi

I will also set up WiFi here. It's an IoT device, so you want to connect wirelessly anyway. With adb connect successful at the command prompt > adb shell am startservice -n com.google.wifisetup/.WifiSetupService -a WifiSetupService.Connect -e ssid <Network_SSID> -e passphrase <Network_Passcode>

To check the connection, use the following command. > adb shell logcat -d | grep Wifi There are various things, but if the following result is displayed, it is successful. V WifiWatcher: Network state changed to CONNECTED V WifiWatcher: SSID changed: ... I WifiConfigurator: Successfully connected to ...

Google Assistant sample clone

Clone the following repositories from Github. https://github.com/androidthings/sample-googleassistant Next, set the Google Console according to the ReadMe.

Creating a Google API Console Project

https://developers.google.com/assistant/sdk/prototype/getting-started-other-platforms/config-dev-project-and-account Follow this page to set up the Google API.

  1. Create a new project from here. Enter the project name and press OK.
  2. Go to the API library and search for Assistant. Enable the Google Assistant API.
  3. Go to Credentials and create the credentials. Create an OAuth Client ID. Please enter only the service name to be displayed to the user on the Oauth consent screen. Set the application type to other, enter a name and save.
  4. A dialog box will appear, but close it.
  5. Click the download button (↓) on the right side of the OAuth 2.0 client ID list. Save the Google Assistant to the cloned directory with the file name client_secret_ <client-id> .json.

Activity management settings

To use Assistant, allow activities from the following https://myaccount.google.com/activitycontrols Turn on the following items

--Web and app activity --Location history --Terminal information --Voice activity

Install google-auth-oauthlib

https://github.com/GoogleCloudPlatform/google-auth-library-python-oauthlib Install google-auth-oauthlib using pip (python's package management system). (If you don't have Python installed, install it here. Either 2 or 3 is OK) Start a command prompt and enter the following command > pip install google-auth-oauthlib

Launch Android Studio

Start Android Studio and open the project in the directory where you cloned Google Assistant. Also, at this timing, change one line of source code on Android Studio. Set the variable on line 61 of app> java> AssistantActivity.java to false. private static final boolean AUDIO_USE_I2S_VOICEHAT_IF_AVAILABLE = false; After making changes, save the file.

Working on the command prompt

Make the working directory of the command prompt a cloned directory of Google Assistant and enter the following command. For client_secret_NNNN.json, specify the file saved in 5 of Creating Google API Console Project.

google-oauthlib-tool --client-secrets client_secret_NNNN.json --credentials app/src/main/res/raw/credentials.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save

The browser will start automatically and the authentication screen will appear, so select Allow. It's okay to close the page when the screen changes.

Then enter the following command. > gradlew assembleDebug > adb install -g app/build/outputs/apk/app-debug.apk It should succeed if the Raspberry Pi 3 is connected. If it fails, check the connection with ʻadb connect [IP address]`.

Finally, run (▶) in Android Studio. The app will be placed and launched. After waiting for a while, press the switch and try talking in English. If you get a response, you are successful. Thank you for your hard work.

Summary

I briefly wrote down what I did from scratch to moving the sample. Android Things has little Japanese information, but I think it is an attractive service, such as Google's API can be used on IoT terminals. Assistant's response is quick. In the next step, we will actually create an app. Thank you for reading this far.

Recommended Posts

Until the Google Assistant sample runs on Android Things
Scala runs on the JVM
[Android] Get the date on Monday
Watson Assistant (formerly Conversation) on Android
Try using the service on Android Oreo
Sample to display (head-up) notifications on Android
[Android] Get the tapped position (coordinates) on the screen
Until you start developing android apps on mac
[Android] List all setting items on the setting screen
Until you run the Apache Velocity sample code