android - 如何在wearOS android中默认添加并发症
问题描述
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();
}
推荐阅读
- python - 如何在列表中找到特定长度的重复序列?
- python - ELI5:什么是 Django?
- c# - 如何在c#中查找或计算多维数组中的重复项
- android - 在查询中使用 get() 和 exists() 规则获取缺少或不足的权限
- javascript - 可以为网格区域属性设置动画吗?
- linux - 如何编写 git 命令来分隔历史文件?
- reactjs - 解决 axios 请求后组件状态未更新
- git - 致命:不支持协议“https”
- ios - 更新 GoogleMaps 和 GooglePlaces pod 后 iOS 在发布时崩溃
- php - 基于 PDO 数组对象生成字段集组