A bug has cropped up recently in one of my Wear OS (Android Wear)-enabled apps whereby the Service on the mobile device never reacts when the wearable sends it data.
While troubleshooting the root cause, I've noted that the onCreate() method of WearableListenerService is never called. Likewise, the onStartCommand() method from the Service superclass is never called, which I take to mean the Service is indeed not running.
The Service is defined in AndroidManifest.xml, so I can't understand why it's not running anymore.
Below are some code snippets from a new project, where all I do is define a WearableListenerService and try to get it to start. Note that this is to define a Service which runs on a mobile device:
WearMessageListenerService.java
package com.example.test.wearlistenertest;
import android.content.Intent;
import android.util.Log;
import com.google.android.gms.wearable.WearableListenerService;
public class WearMessageListenerService extends WearableListenerService {
@Override
public void onCreate() {
super.onCreate();
Log.v("test", "onCreate()");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.v("test", "onStartCommand()");
return super.onStartCommand(intent, flags, startId);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test.wearlistenertest">
<application
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.example.test.wearlistenertest.WearMessageListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.MESSAGE_LISTENER" />
<data android:scheme="wear" android:host="*" />
</intent-filter>
</service>
</application>
</manifest>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.test.wearlistenertest"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
compile 'com.google.android.gms:play-services-wearable:11.8.0'
}
Neither of the Log.v() methods above output anything on run. I've tested on API 23 and 27.
I'd really appreciate some help with this, as I can't understand why I can't get a basic Service to start. I'm happy to provide any additional details. Many thanks in advance for any assistance offered. - Aaron