Android Wear - 从手持动作开始磨损活动

TWi*_*lly 5 android android-notifications wear-os

我正在从Android手持设备向android服装设备发送通知.我想在android设备上添加一个启动活动的通知操作.

如何将待处理意图设置为磨损设备上的活动?如果在可穿戴设备上创建通知,我可以启动活动,但如果通知是在手机上创建然后发送到可穿戴设备,则无法启动.

 // 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();
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试推出的磨损应用程序的活动清单:

    <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>
Run Code Online (Sandbox Code Playgroud)

Way*_*ski 5

查看Android SDK Manager for API 20中包含的DataLayer示例.它包含一个示例,说明在用户按下移动设备上的按钮后如何在可穿戴设备上启动活动.


Bud*_*ius 0

可能是通过一些黑客手段完成的。

创建您自己的操作并让 Wear.activity<intent-filter来使用它。就像是:

    <intent-filter>
        <action android:name="com.myCompany.myApp.ACTION.openWearActivity" />
    </intent-filter>
Run Code Online (Sandbox Code Playgroud)

然后根据从手机创建的通知意图,您知道这一点,只需使用该意图即可:

new Intent("com.myCompany.myApp.ACTION.openWearActivity");
Run Code Online (Sandbox Code Playgroud)

瞧!