Android Wear App not showing up in “Start…” menu o

2019-07-25 12:00发布

问题:

I have added a wear module to my Android Application in Android Studio. In the mobile module, I have specified this line in the mobile applications build.gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:+'
    compile "com.android.support:support-v4:20.0.+"
    wearApp project(':wear')
}

Also, here is my AndroidManifest.xml for the wear module.

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

In logcat, I see the messages that the application is installed on the watch.

09-16 17:12:03.075: D/WearablePkgInstaller(1023): Got PackageUpdateReceiver message Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.myapplication flg=0x4000010 cmp=com.google.android.wearable.app/com.google.android.clockwork.companion.packagemanager.PackageUpdateReceiver (has extras) }

However, I can't go to Start... to find the application! Is there something obvious I'm missing?

回答1:

Make sure that your AndroidManifest.xml includes something like:

<activity
    android:name=".MyActivity"
    android:label="MyActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

(Assuming in the above example that the Activity you want to launch from Start is com.myapplication.MyActivity, and that you want it to show up in the Start list as "MyActivity".)



回答2:

Maybe you forgot to declare the activity to the launcher in the manifest. Do you have an activity with theses filters?

<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />


回答3:

I was missing this line from the wearable AndroidManifest.xml

More specifically, this needs to be in the application section of the xml structure.

<application
    android:icon="@drawable/ic_launcher"
    ... >

    <meta-data android:name="com.google.android.clockwork.home.preview" 
        android:resource="@drawable/ic_launcher" />