Android 没有 Activity 的可穿戴应用

Android Wearable app with no Activity

我正在创建一个用于扩展手持应用程序通知的穿戴式应用程序。 我编写了一个 wear 模块(一个单独的 wear 应用程序),因为我需要我的手持设备和可穿戴设备在通知时表现不同。

通过为 wear 创建一个单独的应用程序,它现在可以在我的 wear 设备上启动(默认情况下,我得到 Activity 说 "Hello Square World!")。

有没有办法让我的 Wear 应用程序在没有启动选项的情况下存在?

正如 tyczj 所说,如果您正在使用服务,则不需要 activity。

要能够通过 Android Studio run/debug 执行此操作,您必须编辑 Wear 应用程序的 Run/Debug 配置并在 Activity 下指定 "Do not launch activity"部分。

这是我的清单示例,它只是一个 wear 监听器服务。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.codechimp.myapp" >

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-feature android:name="android.hardware.type.watch" />

    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault" >

        <service android:name=".WearListenerService">
            <intent-filter>
                <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
            </intent-filter>
        </service>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>

</manifest>

在 Android Studio 3.1.2 中,

  1. 点击"Edit Configurations"

  1. Select "wear" 模块和 select "Nothing" 启动选项。