android - 如何在 wearOS android 中默认添加并发症

标签 android wear-os android-wear-2.0 watch-face-api android-wear-complication

Developer.android 说:

void setDefaultSystemComplicationProvider (int watchFaceComplicationId, int 系统提供者, 整型)

但对我不起作用。

最佳答案

作为一名 Android 开发新手,由于缺乏适用于 Wear OS 平台的社区支持和教程,我很难在默认情况下为 Wear OS 设置复杂功能。通过对我的代码进行一些调整,我以某种方式设法使该方法对我有用。我想分享给可能对他们有帮助的人。 这是我用过的方法:

private void initializeComplications() {
    Log.d("complication", "initializeComplications()");

    mActiveComplicationDataSparseArray = new SparseArray<>(COMPLICATION_IDS.length);

    ComplicationDrawable leftComplicationDrawable =
            (ComplicationDrawable) getDrawable(R.drawable.custom_complication_styles);
    leftComplicationDrawable.setContext(getApplicationContext());

    ComplicationDrawable rightComplicationDrawable =
            (ComplicationDrawable) getDrawable(R.drawable.custom_complication_styles);
    rightComplicationDrawable.setContext(getApplicationContext());

    ComplicationDrawable topComplicationDrawable =
            (ComplicationDrawable) getDrawable(R.drawable.custom_complication_styles);
    topComplicationDrawable.setContext(getApplicationContext());

    mComplicationDrawableSparseArray = new SparseArray<>(COMPLICATION_IDS.length);
    mComplicationDrawableSparseArray.put(LEFT_COMPLICATION_ID, leftComplicationDrawable);
    mComplicationDrawableSparseArray.put(RIGHT_COMPLICATION_ID, rightComplicationDrawable);
    mComplicationDrawableSparseArray.put(TOP_COMPLICATION_ID, topComplicationDrawable);

    // Set default complication
    // This time we don't create a setting screen so we need to set it here
    setDefaultSystemComplicationProvider (
            LEFT_COMPLICATION_ID,
            SystemProviders.STEP_COUNT,
            ComplicationData.TYPE_SHORT_TEXT);

    setDefaultSystemComplicationProvider (
            RIGHT_COMPLICATION_ID,
            SystemProviders.WATCH_BATTERY,
            ComplicationData.TYPE_SHORT_TEXT);

    setDefaultSystemComplicationProvider (
            TOP_COMPLICATION_ID,
            SystemProviders.DATE,
            ComplicationData.TYPE_SHORT_TEXT);

    setActiveComplications(COMPLICATION_IDS);
}

最后我调用了它:

public void onCreate(SurfaceHolder holder) {

    setWatchFaceStyle(new WatchFaceStyle.Builder(DigitalPrayerTimes.this)
            .setAcceptsTapEvents(true)
            .build());

    // TODO: Step 2, intro 3
    initializeComplications();
}

关于android - 如何在 wearOS android 中默认添加并发症,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57986725/

相关文章:

java - 不选择如何传递微调器值

Android AlarmManager.set(...) : notification never received when battery low

Android.Support.Wearable.Comapnion.WatchFaceCompanion 不会导入 Android Studio

java - Android Wear 数据层中的 PutDataMapRequest 对象

android - 无法在 Google Play 开发者控制台中的 Android Wear 上分发应用

Android Wear 2 WiFi本地网络接入

wear-os - 删除 WearableRecyclerView 多余的顶部空间

android - MediaController上的“播放/暂停”按钮不会单独刷新音频播放器

android - 如何在 Kotlin 中使用 MPAndroidChart 为条形图添加带有一些详细信息的标记?

java - Android Wear 无法唤醒屏幕