Search code examples
androidwear-osgoogle-api-clientandroid-intentserviceandroid-wear-data-api

How to start an activity with a custom layout from Wearable when Handheld device receives a Push Notification


I am trying to launch an Activity form a Wearable device (watch) when a push notification is received on a handheld device.

I read in other questions that I will need to send data over to Wearable, then in the "onDataChanged" event I can build the notification from the wearable device and add a PendingIntent with the desired wearable activity. But in order to do that I will have to initialize and connect a GoogleAPIClient from the intent service on the handheld device that received the push nitification which is the part that I am kind of struggling with. Any help would be appreciated. Thanks.


Solution

  • Since I am trying to connect the ApiClient from a service that does not run on the UI thread I was able to do that

     mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(Wearable.API).build();
     mGoogleApiClient.blockingConnect(30, TimeUnit.SECONDS);
    

    And it worked fine.