Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Wear - start wear activity from handheld action

I'm sending a notification from an android handheld device to an android wear device. I'd like to include an action with the notification that starts an activity on the android wear device.

How do I set the pending intent to an activity on the wear device? I'm able to launch the activity if the notification is created on the wearable, but not if the notification is created on the phone and then sent to the wearable.

 // creating action for push notification created on handheld
 public NotificationCompat.Action CreateWearAppAction(Integer metricId) {
    // I wasnt able to look up the wear's main activity class since this is in the handheld project.
    Intent wearPageIntent = new Intent(Intent.ACTION_VIEW);
    Uri wearUri = Uri.parse("mywearapp://Test?MetricId=" + metricId);
    wearPageIntent.setData(wearUri);
    PendingIntent wearPagePendingIntent = PendingIntent.getActivity(context, 0, wearPageIntent, 0);

    return new NotificationCompat.Action.Builder(R.drawable.ic_action_metric,
            "Open Charts on Wear", wearPagePendingIntent)
            .build();
}

Activity manifest from wear app that I'm trying to launch:

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:noHistory="true"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <!-- deep link -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="mywearapp" />
        </intent-filter>
    </activity>
like image 832
TWilly Avatar asked Aug 06 '14 18:08

TWilly


1 Answers

Have a look at the DataLayer sample included in the Android SDK Manager for API 20. It contains an example of how to start up an activity on the wearable after a user presses a button on the mobile device.

like image 73
Wayne Piekarski Avatar answered Sep 27 '22 20:09

Wayne Piekarski