Android Wearable app with no Activity

2019-07-07 11:28发布

问题:

I'm creating a wear app that is used to extend my handheld app's notifications. I wrote a wear module (a separate wear app) because I needed my handheld and wearable devices to behave differently with their notifications.

By creating a separate app for wear, it can now be launched on my wear device (by default, I get the Activity saying "Hello Square World!").

Is there a way for my wear app to exists without the option to launch it?

回答1:

As tyczj stated you don't need an activity if you are using service.

To be able to run/debug this via Android Studio you must edit the Run/Debug configuration for the wear app and specify "Do not launch activity" under the Activity section.

Here's a sample of my manifest, it's just a wear listener service.

<?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>


回答2:

In Android Studio 3.1.2,

  1. Click "Edit Configurations"

  1. Select "wear" module and select "Nothing" for Launch options.