【问题标题】:How to perform a click on a button on wearable and trigger another button on the handheld?如何在可穿戴设备上单击一个按钮并触发手持设备上的另一个按钮?
【发布时间】:2016-03-13 21:35:03
【问题描述】:

我在手机上有一个带有 1 个按钮的应用程序。我想通过 android wear 触发这个按钮。我该怎么做?

java 代码仍然是 Android Studio 创建的标准,我将禁止它们。

佩戴xml代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="br.com.teste.wearbuttonclick.WearMainActivity"
    tools:deviceIds="wear"
    android:background="#5c6bc0"
    >

    <TextView
        android:id="@+id/clock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|start"
        android:textColor="@android:color/white"
        app:layout_box="all" />

    **<Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:text="Click"
        android:background="#5c6bc0"
        android:textColor="#ffffff"
        android:id="@+id/wearbutton"
        />**


</android.support.wearable.view.BoxInsetLayout>

移动 xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="br.com.teste.wearbuttonclick.MobileMainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Target Button"
        android:id="@+id/mobilebutton"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

【问题讨论】:

  • 我建议您阅读 Wear 开发以及如何在可穿戴设备和连接的手机之间发送消息,尽力完成您的想法,然后返回一些具体的编码问题。就目前而言,您要求人们为您编写应用程序。概括地说,您捕获穿戴应用上的点击,向连接的手机应用发送消息,在手机端捕获该消息并触发点击。
  • Ali Naddaf,我不是要你为我编写应用程序。我已经有一个功能齐全的应用程序。我只需要在 android wear 中实现这个附加功能。你的回答很模糊。我希望其他人愿意帮助我。我研究了 android wear 文档,但无法使其工作。

标签: android wear-os android-button


【解决方案1】:

您好,点击可穿戴应用按钮发送消息,并在手持设备 onMessageReceived() 中使用您的按钮名称调用此方法:-

private void makeClick() {
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "clicked", Toast.LENGTH_LONG).show();
        }
    });
    button.performClick();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多