Watch Face Complication选择器从未显示过

时间:2016-10-26 11:34:59

标签: android wear-os android-wear-2.0 android-wear-complication

我正在尝试为我的手表实施复杂功能支持。这是我的AndroidManifest。

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

    <uses-feature android:name="android.hardware.type.watch"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA"/>

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

        <!-- Watch Face -->

        <service
            android:name=".ComplicationSimpleWatchFaceService"
            android:enabled="true"
            android:label="Fancy Watch"
            android:permission="android.permission.BIND_WALLPAPER">
            <meta-data
                android:name="android.service.wallpaper"
                android:resource="@xml/watch_face"/>
            <meta-data
                android:name="com.google.android.wearable.watchface.preview"
                android:resource="@drawable/preview_complication_simple"/>
            <meta-data
                android:name="com.google.android.wearable.watchface.preview_circular"
                android:resource="@drawable/preview_complication_simple"/>
            <meta-data
                android:name="com.google.android.wearable.watchface.wearableConfigurationAction"
                android:value="com.example.wearapp.CONFIG_COMPLICATION_SIMPLE"/>

            <intent-filter>
                <action android:name="android.service.wallpaper.WallpaperService"/>

                <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
            </intent-filter>
        </service>

        <activity android:name="android.support.wearable.complications.ComplicationHelperActivity"/>
        <activity
            android:name=".ComplicationSimpleConfigActivity"
            android:label="Fancy Watch">
            <intent-filter>
                <action android:name="com.example.wearapp.CONFIG_COMPLICATION_SIMPLE"/>

                <category android:name="com.google.android.wearable.watchface.category.WEARABLE_CONFIGURATION"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

    </application>

</manifest>

我有一个监视面部服务和一个配置活动。当我使用ComplicationHelperActivity从配置活动创建ProviderChooserHelperIntent时,我总是在onActivityResult中取消结果。以下是我开始选择活动并听取结果的方法

   @Override
        public void onClick(WearableListView.ViewHolder viewHolder) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "onClick()");
            }

            Integer tag = (Integer) viewHolder.itemView.getTag();
            ComplicationItem complicationItem = mAdapter.getItem(tag);

            startActivityForResult(ComplicationHelperActivity.createProviderChooserHelperIntent(
                            getApplicationContext(),
                            complicationItem.watchFace,
                            complicationItem.complicationId,
                            complicationItem.supportedTypes),
                    PROVIDER_CHOOSER_REQUEST_CODE);
        }


       @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (requestCode == PROVIDER_CHOOSER_REQUEST_CODE
                    && resultCode == RESULT_OK) {
                ComplicationProviderInfo complicationProviderInfo =
                   data.getParcelableExtra(ProviderChooserIntent.EXTRA_PROVIDER_INFO);
                Log.d(TAG, "Selected Provider: " + complicationProviderInfo);
                finish();
            }
        }

似乎我缺少并发症支持,这就是为什么不能选择任何提供者。但为了测试这个,我从WatchFace示例复制了ComplicationSimpleWatchFaceService,但仍然没有任何结果。这是表盘的复杂功能代码。

  private static final int LEFT_DIAL_COMPLICATION = 0;
    private static final int RIGHT_DIAL_COMPLICATION = 1;

    public static final int[] COMPLICATION_IDS = {LEFT_DIAL_COMPLICATION, RIGHT_DIAL_COMPLICATION};

    public static final int[][] COMPLICATION_SUPPORTED_TYPES = {
            {ComplicationData.TYPE_SHORT_TEXT},
            {ComplicationData.TYPE_SHORT_TEXT}
    };


    private void initializeComplication() {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "initializeComplications()");
            }
            mActiveComplicationDataSparseArray = new SparseArray<>(COMPLICATION_IDS.length);

            mComplicationPaint = new Paint();
            mComplicationPaint.setColor(Color.WHITE);
            mComplicationPaint.setTextSize(COMPLICATION_TEXT_SIZE);
            mComplicationPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
            mComplicationPaint.setAntiAlias(true);

            setActiveComplications(COMPLICATION_IDS);
        }

1 个答案:

答案 0 :(得分:0)

确保您已调用ComplicationHelperActivity.createProviderChooserHelperIntent方法,以获取意图并启动提供商选择器。

示例代码(确保调用getActivity()方法启动它):

startActivityForResult(
  ComplicationHelperActivity.createProviderChooserHelperIntent(
     getActivity(),
     watchFace,
     complicationId,
     ComplicationData.TYPE_LARGE_IMAGE),
  PROVIDER_CHOOSER_REQUEST_CODE);

意图可与startActivitystartActivityForResult一起使用以启动选择器。

您可以按照此tutorial查看是否遗漏了某些配置。