Nearby Messages API for Androidの Get Started を翻訳してみました。
お気づきの点があればコメント頂ければと思います。
以下、関連する投稿へのリンクです。
■ Google Play services Nearby 公式 翻訳
■ Nearby Messages API (Overview) 公式 翻訳
■ Nearby Messages API for Android (Get Started) 公式 翻訳
■ Nearby Messages API for Android (Publish and Subscribe) 公式 翻訳
Get Started
This document explains how to start developing with the Nearby Messages API on Android. The Nearby Messages API is part of Google Play services.
このドキュメントでは、Android上でNearby Messages APIで開発を始める方法について説明します。 Nearby Messages APIはGoogle Play servicesに含まれています。
Step 1: Get Google Play services
The Nearby Messages API is available on Android devices with Google Play services 7.8.0 or higher. Devices running Android 2.3 or higher that have the Google Play Store app automatically receive updates to Google Play services. To check which version of Google Play services is installed on your device, go to Settings > Apps > Google Play services. Ensure that you have the latest client library for Google Play services on your development host:
- Open the Android SDK Manager.
- Under Appearance & Behavior > System Settings > Android SDK > SDK Tools, ensure that the following packages are installed:
- Google Play services
- Google Repository
Nearby Messages APIはGoogle Play services7.8.0以降のAndroidデバイスで利用可能です。 Google Play StoreアプリのあるAndroid 2.3以降のデバイスは自動でGoogle Play servicesの更新を受信します。 あなたのデバイスにインストールされているGoogle Play servicesのバージョンを確認するには、Settings > Apps > Google Play servicesに移動します。 あなたの開発機にGoogle Play servicesの最新のクライアントライブラリがあることを確認します。
-
Android SDK Managerを開きます。
-
Appearance & Behavior > System Settings > Android SDK > SDK Toolsを開き、下記のパッケージがインストールされていることを確認します:
- Google Play services
- Google Repository
Step 2: Get a Google account
To use the Nearby Messages APIs, you need a Google Account. If you already have an account, then you're all set. You may also want a separate Google Account for testing purposes.
Nearby Messages APIを使用するため、Google Accountが必要です。 すでにアカウントがある場合、あなたは全て設定済みです。 またあなたはテスト用に別のGoogleアカウントを必要とするかもしれません。
Step 3: Get an API key
Take these steps to enable the Google Nearby Messages API for Android and get an API key:
- Go to the Google Developers Console.
- Create or select a project to register your application with.
- Click Continue to Enable the API.
- On the Credentials page, create a new Android key (and set the API Credentials).
Note: If you have an existing Android key, you may use that key. - In the resulting dialog, enter your app's SHA-1 fingerprint and package name. For example:
BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75
com.example.android.nearbyexample
- Your new Android API key appears in the list of API keys for your project. An API key is a string of characters, something like this:
AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0
- To prevent quota theft, secure your API key following these best practices.
Obtain the SHA1 fingerprint of your certificate
To create a new API key for your Android app, you need the SHA1 fingerprint of the certificate you use to sign your APK. Messages can only be exchanged between apps that are signed with API keys from the same project.
To obtain this fingerprint:
1.Find the location of your keystore.
2.In a terminal, run the keytool
utility from the JDK. For example, if you are using the `debug`
keystore:
$ keytool -exportcert -alias \
androiddebugkey -keystore \
~/.android/debug.keystore -list -v
Note: For the debug keystore, the password is android
. On Mac OS and Linux, the debug keystore is typically located at ~/.android/debug.keystore
. On Windows, it is typically located at %USERPROFILE%\.android\debug.keystore
.
3.The output of the keytool
command contains the SHA1 fingerprint for the certicate.
Note: If you are also developing an iOS app, or using the Proximity
Beacon REST API, make sure you generate all respective API keys within
the same Google Developers Console project. For more information,
see the Getting Started guide for iOS, and Get Started with the REST API.
Android向けNearby Messages APIを有効にし、APIキーを取得するには、次の手順を実行します:
-
あなたのアプリを登録するためのプロジェクトを作成または選択します。
-
APIを有効にするため、Continueをクリックします。
-
Credentialsページで、新しいAndroid keyを作成します。(そしてAPI認証を設定します)
注: すでにAndroid keyがある場合、それを使用してもかまいません。 -
表示されるダイアログで、アプリのSHA-1 fingerprintとパッケージ名を入力します。 例:
BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75
com.example.android.nearbyexample
-
あなたの新しいAndroid API keyは、プロジェクトのAPI keyのリストに表示されます。 API keyは、このような文字列です:
AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0
-
クォータの盗難を防止し、API keyを安全に保管するため、ベストプラクティスを参照してください。
あなたの証明書のSHA1 fingerprintを取得する
Androidアプリ用に新しいAPI keyを作成するには、あなたがAPKの署名に使用する証明書のSHA1 fingerprintが必要です。 メッセージは、同じプロジェクトのAPI keyで署名されたアプリ間でのみ交換することができます。
fingerprintを取得するには:
1.keystoreの場所を探します。
2.ターミナルでJDKのkeytool
を実行します。 あなたが`debug`
keystoreを使用しているなら下記の通り:
$ keytool -exportcert -alias \
androiddebugkey -keystore \
~/.android/debug.keystore -list -v
注: debug keystoreのパスワードはandroid
です。 Mac OSとLinuxではdebug keystoreは一般的には~/.android/debug.keystore
にあります。 Windowsでは一般的には%USERPROFILE%\.android\debug.keystore
にあります。
3.keytool
コマンドの出力には証明書のSHA1 fingerprintが含まれます。
注: もしあなたがiOSアプリも作成していたり、またはビーコンREST APIを使用しているなら、必ず全てのAPI keyを、同じGoogle Developers Consoleプロジェクトで生成してください。 詳しくはGetting Started guide for iOSとGet Started with the REST APIを参照してください。
Step 4: Configure your project
Android Studio makes it easy to create a project for the Nearby Messages API. Follow the steps described in Creating a Project to create a new project. In Android Studio, open the build.gradle
file for your module and add the Google Play services client library as a dependency:
apply plugin: 'android'
...
dependencies {
compile 'com.google.android.gms:play-services-nearby:8.4.0'
}
Then, configure your manifest with the API Key generated in the previous step:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.sample.app" >
<application ...>
<meta-data
android:name="com.google.android.nearby.messages.API_KEY"
android:value="API_KEY" />
<activity>
...
</activity>
</application>
</manifest>
Android StudioはNearby Messages APIプロジェクトの作成を容易にします。 新しいプロジェクトを作成するには、プロジェクトの作成に記載されている手順に従ってください。 Android Studioで、モジュールのbuild.gradle
ファイルを開き、Google Play services client libraryを依存関係として追加します:
apply plugin: 'android'
...
dependencies {
compile 'com.google.android.gms:play-services-nearby:8.4.0'
}
次に、前のステップで生成されたAPI keyを使用してマニフェストを設定します:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.sample.app" >
<application ...>
<meta-data
android:name="com.google.android.nearby.messages.API_KEY"
android:value="API_KEY" />
<activity>
...
</activity>
</application>
</manifest>
Step 5: Connect to the Nearby Messages service
In your app, create a GoogleApiClient and add the Nearby Messages API. The following snippet shows how to add the Nearby Messages API:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Nearby.MESSAGES_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
The Nearby Messages API requires user consent. Prior to making requests, your app must check to see whether the user has consented, and present them with a dialog if they have not. See Publish and Subscribe for more information.
GoogleApiClientを作成してNearby Messages APIを追加します。 次のスニペットは、Nearby Messages APIを追加する方法を示しています:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Nearby.MESSAGES_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Nearby Messages APIは、ユーザーの承諾を必要とします。 リクエストを作成する前に、あなたのアプリは、ユーザーが承諾済かどうかをチェックする必要があります。そして未承諾の場合にはダイアログでそれらを提示する必要があります。 詳しくはPublish and Subscribeを参照してください。