0

我正在尝试为我的手表实现复杂功能支持。这是我的 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);
        }
4

1 回答 1

0

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

示例代码(确保调用该getActivity()方法以使其启动):

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

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

您可以按照本教程查看是否遗漏了一些配置。

于 2016-10-27T07:22:04.613 回答