Android Wear - 开始从手持式行动磨损活动 [英] Android Wear - start wear activity from handheld action

查看:165
本文介绍了Android Wear - 开始从手持式行动磨损活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要送从一个Android手持设备的通知在Android设备的磨损。我想包括与启动了Android的磨损设备上的活动通知的动作。

如何设置挂起意图的磨损设备上的活动?我能够如果创建的通知以启动活动上的耐磨,但如果该通知是在电话上创建的,然后发送到穿戴式

  //创建推送通知操作手持创建
 公共NotificationCompat.Action CreateWearAppAction(整数metricId){
    //我不是能找出磨损的主要活动类,因为这是在手持项目。
    意图wearPageIntent =新的意图(Intent.ACTION_VIEW);
    乌里wearUri = Uri.parse(mywearapp://测试MetricId =?+ metricId);
    wearPageIntent.setData(wearUri);
    PendingIntent wearPagePendingIntent = PendingIntent.getActivity(上下文,0,wearPageIntent,0);

    返回新NotificationCompat.Action.Builder(R.drawable.ic_action_metric,
            就穿敞图表,wearPagePendingIntent)
            。建立();
}
 

从磨损的应用程序,我想推出的活动清单:

 <活动
        机器人:名称=。MainActivity
        机器人:标签=@字符串/ APP_NAME
        机器人:noHistory =真
        机器人:出口=真正的>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>
            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>

        <! - 深层链接 - >
        <意向滤光器>
            <作用机器人:名称=android.intent.action.VIEW/>
            <类机器人:名称=android.intent.category.DEFAULT/>
            <类机器人:名称=android.intent.category.BROWSABLE/>
            <数据机器人:计划=mywearapp/>
        &所述; /意图滤光器>
    < /活性GT;
 

解决方案

已经包括在Android SDK管理器API 20.包含如何后启动的活动的可穿戴的例子来看看DataLayer样本用户presses所述移动设备上的按钮。

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>

解决方案

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.

这篇关于Android Wear - 开始从手持式行动磨损活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆