My WearableListenerService is not started when Android wear restarts

2.3k views Asked by At

I have an android Application that (among other things) show notifications on an Android Wear device.

This is done by having a class in the Wear module extend WearableListenerService. In the Wear module, I also have a class that extends BroadcastReceiver.

The scenario here is: - Run the application from Android Studio - Use the phone application so that a Notification is shown on the Wear device - Restart the Wear device

Now what I want is that if I make the phone show another notification, it should appear on the wearable. So is not the case, because the WearableListenerService is not started...

So I let the BroadcastManager listen to ACTION_BOOT_COMPLETED events:

@Override
public void onReceive(Context context, final Intent intent) {
    Log.d(TAG, "onReceive!");
    if(intent==null)
        return;

    if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
        Log.d(TAG, "Action boot completed");
        ComponentName c = context.startService(new Intent(context, OngoingNotificationListenerService.class));
        Log.d(TAG, "returned " + c);
        return;
    }
    .
    .
    .

And in my Manifest file:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
.
.
.
<receiver android:name=".ActionsReceiver" android:enabled="true" android:exported="false">
        <intent-filter>
            <action android:name="com.XX.receiver.action_pause" />
            <action android:name="com.XX.receiver.action_resume" />
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
</receiver>

Now the problem is that my application doesn't receive the BOOT_COMPLETED action. I have checked the log and seen that the other listeners on the watch receives this event after a reboot, but not mine.

I have seen several posts about this, for example Android BOOT_COMPLETED not received when application is closed

I think this might be quite similar to my problem.

My android wear app doesnt have a "mainactivity" that a user can start - it's ONLY the listener service and receiver. Although, I quickly implemented a main activty with a launcher intent, so that I could launch the app from the launcher on the watch. This didn't affect the situtation at all. Once the watch is restarted, it wont show a notification from my app until I reinstall it from android studio.

So have I missed something important? Is my WearableListenerService supposed to start itself without my interaction when the watch is restarted? (It doesn't...) Or does it have anything to do with that this is a developer version of the app?

(Note: I have also tried shut down and then start - no difference)

2

There are 2 answers

0
Tony Malghem On

Try adding <category android:name="android.intent.category.DEFAULT" /> as a child of you <intent-filter>

2
Entreco On

You need to add your service to your wear module's manifest and add the BIND_LISTENER DATA_CHANGED action to it:

To listen to data items and messages on a path of /prefix, the new syntax looks like this (according to the android tools site):

<service android:name=".ExampleWearableListenerService">
    <intent-filter>
        <action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
        <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
        <data android:scheme="wear" android:host="*" android:pathPrefix="/prefix" />
    </intent-filter>
</service>