0
私はappとapp wearとの通信を制御するサービスを1つ持っていますが、このサービスではデバッグ時に決してメソッドに入りません。WearableListenerServiceはアプリケーション内に作成されていません
AndroidManifest
<service android:name=".ElUniversalWearService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<data android:scheme="wear" android:host="*"
android:path="/start-activity" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
</intent-filter>
ElUniversalWearService
public class ElUniversalWearService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
private GoogleApiClient googleApiClient=null;
private Node connectedNode=null;
@Override
public void onCreate() {
super.onCreate();
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.build();
googleApiClient.connect();
}
@Override
public void onMessageReceived(MessageEvent messageEvent) {
super.onMessageReceived(messageEvent);
String message=messageEvent.getPath();
if(message.equals(Operations.MESSAGE_INTERNET_VERIFY)){
new InternetAsynkTask().execute();
Log.d("[DEBUG-APP]", "Checa la conexión");
}
}
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
Log.e("[DEBUG-APP]", "Lee la información enviada desde el wear");
for (DataEvent event : dataEvents) {
String eventUri = event.getDataItem().getUri().toString();
if (eventUri.contains(Operations.SECTION_REQUEST)) {
DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
String notesDataMaps = dataMapItem.getDataMap().getString(TagName.ARG_NAME_SECTION);
String urlNoteDataMaps = dataMapItem.getDataMap().getString(TagName.ARG_NAME_SECTION);
new SendDataNoteTask(googleApiClient).execute(urlNoteDataMaps);
}
}
}
public void sendMessageToWear(String message){
new SendMessageTask(googleApiClient).execute(message);
}
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.e("[DEBUG-APP]", "Se ha conectado al wear");
}
@Override
public void onConnectionSuspended(int i) {
Log.e("[DEBUG-APP]", "Se ha suspendido el wear");
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.e("[DEBUG-APP]", "Se ha fallado al conectar al wear");
}
private class InternetAsynkTask extends AsyncTask<Void,Void,Boolean>{
@Override
protected Boolean doInBackground(Void... params) {
if(CheckNetworkConnection.isConnectionAvailable(getBaseContext())){
return true;
}else{
return false;
}
}
@Override
protected void onPostExecute(Boolean aBoolean) {
if(aBoolean)
sendMessageToWear(Operations.MESSAGE_INTERNET_ENABLED);
else
sendMessageToWear(Operations.MESSAGE_INTERNET_DISABLED);
}
}
}