À compter de la version 4.5 du SDK Android, une nouvelle extension Android a été ajoutée pour permettre la collecte des données à partir de l’application Android Wearable.
Pour plus d’informations sur l’importation du SDK dans votre projet, voir Mise en œuvre principale et cycle de vie.
Ajoutez le fichier ADBMobileConfig.json
au dossier assets du projet.
Ajoutez le fichier adobeMobileLibrary-*.jar
au dossier libs ou assurez-vous que ce fichier est référencé par le projet.
Vous devrez peut-être synchroniser le projet gradle après l’ajout du fichier .jar
.
Pour la méthode onCreate
, autorisez le SDK à accéder au contexte de l’application à l’aide de Config.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());
}
Ajoutez le code suivant au AndroidManifest.xml
fichier :
<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>
Assurez-vous que votre projet comprend la bibliothèque des services Google Play.
Mettez en œuvre WearableListenerService
ou ajoutez le code correspondant à 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);
}
}
Ajouter WearListenerService
au fichier AndroidManifest.xml
:
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?lang=fr" />
</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
Procédez de l’une des manières suivantes :
Ajoutez le même fichier ADBMobileConfig.json
au dossier assets de votre projet wearable.
Modifiez la configuration du projet gradle afin d’utiliser le fichier ADBMobileConfig.json
dans le dossier assets de l’application pour portables :
android {
sourceSets {
main {
assets.srcDirs = ['src/main/assets','../mobile/src/main/assets']
}
}
}
Ajoutez le fichier adobeMobileLibrary-*.jar
au dossier libs ou assurez-vous qu’il est référencé par le projet.
Vous devrez peut-être synchroniser le projet gradle après l’ajout du fichier jar.
Pour la méthode onCreate
, permettez au SDK d’accéder au contexte de votre application en utilisant Config.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);
}
Ajoutez le code suivant à AndroidManifest.xml
:
<application>
.......
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
Assurez-vous que votre projet comprend la bibliothèque de services de Google Play.
Mettez en œuvre WearableListenerService
ou ajoutez le code correspondant à WearableListenerService
:
public class WearListenerService extends WearableListenerService {
@Override
public void onDataChanged(com.google.android.gms.wearable.DataEventBuffer dataEvents) {
DataListenerWearable.onDataChanged(dataEvents);
}
}
Ajouter WearListenerService
au fichier AndroidManifest.xml
:
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?lang=fr" />
</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