Developer.android 说:
void setDefaultSystemComplicationProvider (int watchFaceComplicationId, int systemProvider, int type)
但对我不起作用。
Developer.android 说:
void setDefaultSystemComplicationProvider (int watchFaceComplicationId, int systemProvider, int type)
但对我不起作用。
作为一名初级 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();
}