0

I need to implement a fullscreen activity on a Wear device that is started when the user swipes to the next page of the notification - like the demo card "Boarding pass" (QR code on second page).

The activity needs to be animated.

My questions: how can I create this activity when the code runs completely on my phone? The notification just references a local class. How does that work? Will the activity class be uploaded to the Wear device? To what extent will I be able to animate the activity? Will I be able to use the device's APIs?

I'm not sure how that is supposed to function.

corazza
  • 31,222
  • 37
  • 115
  • 186

3 Answers3

0

Create an application for the wearable. http://developer.android.com/training/wearables/apps/index.html

gatlingxyz
  • 781
  • 6
  • 12
  • Yes, that is my other option. But I don't know how to start the app when a user interacts with the – corazza Aug 08 '14 at 18:34
  • Your comment got cut off.. What exactly do you need help with? – gatlingxyz Aug 11 '14 at 14:44
  • God damn it, it's supposed to end with "notification". I don't know how to open the app when the users swipes to the left. That screen usually reveals either action buttons or custom activities - which are limited because they run on the phone and can basically be an image, if I'm not mistaken. I currently start the app by a contentAction button, but I'd like to start it when the user swipes. – corazza Aug 11 '14 at 17:40
0

A fullscreen image within the notification is not done via an activity, instead it is a page added to the Notification:

NotificationCompat.Builder builder; // Your notification

Bitmap photo; // Your photo to show full screen
Notification photoPage = new NotificationCompat.Builder(mContext)
    .setStyle(new NotificationCompat.BigPictureStyle()
        .bigPicture(photo))
    .extend(new NotificationCompat.WearableExtender()
        .setHintShowBackgroundOnly(true)) // show full screen
    .build();

NotificationCompat.WearableExtender wearableExtender =
    new NotificationCompat.WearableExtender();
wearableExtender.addPage(photoPage);

builder.extend(wearableExtender);

Notification notification = builder.build(); // Notification with image page
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • Key point: the activity has to be animated. Essentially I'll need a canvas on it. – corazza Aug 08 '14 at 20:33
  • You can't animate from a notification - they're static. At best your notification could have an action that takes you to an activity within a wearable app but that doesn't sound like exactly what you want either – ianhanniballake Aug 08 '14 at 20:38
  • @ianhanniballae OK, that makes sense. Also, opening a new activity is a completely acceptable solution, but I don't know how can I achieve it? How can I reference an Activity class from the wear device in code that belongs to mobile? – corazza Aug 09 '14 at 10:51
0

You need to use e.g. a message (MessageApi) to trigger your wear application from your mobile application. You can also listen for data changes (DataApi).

Update from comment:

Create a subclass of WearableListenerService and listen for changes on either the message or data APIs, I'd recommend the message API:

public class SomeService extends WearableListenerService {
    @Override
    public void onMessageReceived(MessageEvent messageEvent) {
        super.onMessageReceived(messageEvent);
        Log.d(TAG, "onMessageEvent: " + messageEvent);
        if (messageEvent.getPath().equals("/launchApp")) {
            postNotification();
        }
    }

Remember to also declare the correct intent filter in your wear app's AndroidManifest.xml:

    <service
        android:name=".SomeService"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
        </intent-filter>
    </service>
Sveinung Kval Bakken
  • 3,715
  • 1
  • 24
  • 30
  • Thank you. If you don't mind, could you tell me how the service that is supposed to listen to the data changes is started? And how am I supposed to test it? My current setup is a physical S3 and a virtual Wear device. – corazza Aug 08 '14 at 20:32
  • I'd recommend you creating a [WearableListenerService](https://developer.android.com/reference/com/google/android/gms/wearable/WearableListenerService.html) and override either `public void onDataChanged(DataEventBuffer events)` or `public void onMessageReceived(MessageEvent)`. You also need to declare an intent filter for your service in your wear app's `AndroidManifest.xml`. The action is `com.google.android.gms.wearable.BIND_LISTENER` and your service needs to be marked as `android:exported="true"`. – Sveinung Kval Bakken Aug 11 '14 at 13:19
  • I figured it out with the help [from this answer](http://stackoverflow.com/a/24625475/924313). Your comment is basically suggesting the same thing. – corazza Aug 11 '14 at 13:21