Android SDK バージョン 4.5 から新しい Android 拡張機能が追加され、Android ウェアラブルアプリからデータを収集できるようになりました。
SDK をプロジェクトに読み込む方法について詳しくは、「コア実装とライフサイクル」を参照してください。
ADBMobileConfig.json
ファイルをプロジェクトの assets フォルダーに追加します。
adobeMobileLibrary-*.jar
ファイルを libs フォルダーに追加するか、このファイルをプロジェクトで参照されるように設定します。
.jar
ファイルを追加した後で gradle プロジェクトを同期することが必要になる場合があります。
onCreate
メソッドで、Config.setContext
を使用して SDK がアプリケーションコンテキストにアクセスできるようにします。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Allow the SDK access to the application context
Config.setContext(this.getApplicationContext());
}
AndroidManifest.xml
ファイルに次のコードを追加します。
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application>
.......
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
プロジェクトに Google Play サービスライブラリが含まれていることを確認します。
WearableListenerService
を実装するか、対応するコードを WearableListenerService
に追加します。
public class WearListenerService extends WearableListenerService {
@Override
public void onMessageReceived(MessageEvent messageEvent) {
super.onMessageReceived(messageEvent);
}
private GoogleApiClient mGoogleApiClient;
@Override
public void onCreate() {
super.onCreate();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.build();
mGoogleApiClient.connect();
}
@Override
public void onDestroy() {
super.onDestroy();
mGoogleApiClient.disconnect();
}
@Override
public void onDataChanged(com.google.android.gms.wearable.DataEventBuffer dataEvents) {
DataListenerHandheld.onDataChanged(dataEvents, mGoogleApiClient, this);
}
}
AndroidManifest.xml
ファイルに WearListenerService
を追加します。
If you are using Google Play Services < 8.2
<application>
......
<service
android:name=".WearListenerService" >
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
</application>
If you are using Google Play Services >= 8.2
<application>
......
<service
android:name=".WearListenerService" >
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/abdmobile" />
</intent-filter>
</service>
</application>
Please find more information from google's blog https://android-developers.googleblog.com/2016/04/deprecation-of-bindlistener.html.
Permalink Edit
次のどちらかのタスクを実行します。
ADBMobileConfig.json
ファイルをウェアラブルプロジェクトの assets フォルダーに追加します。
ハンドヘルドアプリの assets フォルダーにある ADBMobileConfig.json
を使用するように gradle 設定を変更します。
android {
sourceSets {
main {
assets.srcDirs = ['src/main/assets','../mobile/src/main/assets']
}
}
}
adobeMobileLibrary-*.jar
ファイルを libs フォルダーに追加するか、プロジェクトで参照されるように設定します。
jar ファイルを追加した後で gradle プロジェクトを同期することが必要になる場合があります。
onCreate
メソッドで、Config.setContext
を使用して SDK がアプリケーションコンテキストにアクセスできるようにします。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Allow the SDK access to the application context
Config.setContext(this.getApplicationContext(), Config.ApplicationType.APPLICATION_TYPE_WEARABLE);
}
次のコードを AndroidManifest.xml
に追加します。
<application>
.......
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
プロジェクトに Google Play サービスライブラリが含まれていることを確認します。
WearableListenerService
を実装するか、対応するコードを WearableListenerService
に追加します。
public class WearListenerService extends WearableListenerService {
@Override
public void onDataChanged(com.google.android.gms.wearable.DataEventBuffer dataEvents) {
DataListenerWearable.onDataChanged(dataEvents);
}
}
AndroidManifest.xml
ファイルに WearListenerService
を追加します。
If you are using Google Play Services < 8.2
<application>
......
<service
android:name=".WearListenerService" >
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
</application>
If you are using Google Play Services >= 8.2
<application>
......
<service
android:name=".WearListenerService" >
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/abdmobile" />
</intent-filter>
</service>
</application>
Please find more information from google's blog https://android-developers.googleblog.com/2016/04/deprecation-of-bindlistener.html.
Permalink Edit