0

I have read many posts about this issue but none of them solve my problem. Please, I need help after several days with this problem.

When I run the code in the emulator, mobile and emulator communicate and the service starts, sending it the information and requesting it correctly. But when I run the same code on a real watch, the service does not start.

I have checked in the Wear OS app that Host and Destination are connected. My code is:

NotificationService

public class NotificationService extends WearableListenerService  {
    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "onCreate()"); // NOT called
    }
}

AndroidManifest (wear)

<service android:name=".service.NotificationService" android:exported="true">
     <intent-filter>
                <!-- listeners receive events that match the action and data filters -->
                <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
                <data
                    android:host="*"
                    android:path="/message"
                    android:scheme="wear" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
                <data
                    android:host="*"
                    android:path="/vibrate"
                    android:scheme="wear" />
            </intent-filter>
        </service>

build.gradle (wear)

buildTypes {
        debug {
            signingConfig signingConfigs.myapp
        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.myapp
        }
    }

    implementation 'androidx.wear:wear:1.2.0'
    implementation 'com.google.android.support:wearable:2.9.0'
    implementation 'com.google.android.gms:play-services-wearable:18.0.0'
    compileOnly 'com.google.android.wearable:wearable:2.9.0'
// All my wear libraries are updated

WatchConnGoogle

@Override
    public void sendMessage(Map<String, Object> message) {
        PutDataMapRequest dataMapRequest = PutDataMapRequest.create("/message");
        DataMap dataMap = dataMapRequest.getDataMap();

        for( Map.Entry<String, Object> e: message.entrySet() ) {
            Object value = e.getValue();
            if( value instanceof Integer ) {
                dataMap.putInt( e.getKey(), (int)value );

            } else if( value instanceof Float ) {
                dataMap.putFloat( e.getKey(), (float)value );

            } else if( value instanceof Boolean ) {
                dataMap.putBoolean( e.getKey(), (boolean)value );

            } else if( value instanceof String ) {
                dataMap.putString( e.getKey(), (String)value );

            } else if( value instanceof Bitmap ) {
                dataMap.putByteArray( e.getKey(), toByteArray( (Bitmap)value ) );
            }
        }
        dataMap.putInt( OPEN_APP_ID, openAppId );
        dataMap.putLong( TIME_KEY, System.currentTimeMillis() );

        PutDataRequest request = dataMapRequest.asPutDataRequest();
        request.setUrgent();

        Task<DataItem> dataItemTask = Wearable.getDataClient( context ).putDataItem( request );
    }

Gradle version:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
user3092292
  • 49
  • 2
  • 2
  • 9

0 Answers0