Starting in Android SDK version 4.5, a new Android extension was added that allows you to collect data from your Android Wearable app.
For more information about importing the SDK into your project, see Core Implementation and Lifecycle.
-
Add the
ADBMobileConfig.json
file to the assets folder of your project. -
Add the
adobeMobileLibrary-*.jar
file to the libs folder or make sure this file is referenced by the project.Tip: You might need to sync the gradle project after adding the
.jar
file. -
In the
onCreate
method, allow the SDK access to your application context by usingConfig.setContext
:@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()); }
-
Add the following code to the
AndroidManifest.xml
file:<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>
-
Make sure your project includes the Google play-services library.
-
Implement
WearableListenerService
or add the corresponding code to yourWearableListenerService
: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); } }
-
Add
WearListenerService
to theAndroidManifest.xml
file: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
-
Complete one of the following tasks:
-
Add the same
ADBMobileConfig.json
file to the assets folder of your wearable project. -
Change the gradle config to use the
ADBMobileConfig.json
in the assets folder of the handheld app:android { sourceSets { main { assets.srcDirs = ['src/main/assets','../mobile/src/main/assets'] } } }
-
-
Add the
adobeMobileLibrary-*.jar
file to the libs folder or make sure it get referenced by the project.You might need to sync the gradle project after adding the jar file.
-
In the
onCreate
method, allow the SDK access to your application context usingConfig.setContext
:@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); }
-
Add the following code to
AndroidManifest.xml
:<application> ....... <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> </application>
-
Ensure that your project includes the Google play-services library.
-
Implement
WearableListenerService
or add the corresponding code to yourWearableListenerService
:public class WearListenerService extends WearableListenerService { @Override public void onDataChanged(com.google.android.gms.wearable.DataEventBuffer dataEvents) { DataListenerWearable.onDataChanged(dataEvents); } }
-
Add
WearListenerService
to theAndroidManifest.xml
file: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