Android 安卓磨损,表面型检测-圆形或方形
我有一项活动,例如活动Android 安卓磨损,表面型检测-圆形或方形,android,wear-os,Android,Wear Os,我有一项活动,例如活动 <activity android:name="com.android.ExampleActivity" android:label="@string/app_name" android:allowEmbedded="true"> <intent-filter> <action android:name="android.intent.action.MAIN"
<activity android:name="com.android.ExampleActivity"
android:label="@string/app_name"
android:allowEmbedded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
使用manifiest中的此定义,圆布局检测不会出现问题
但是对于这个修炼者,同样的活动,同样的代码不起作用
<activity android:name="com.android.ExampleActivity"
android:label="@string/app_name"
android:allowEmbedded="true">
<meta-data android:name="com.google.android.clockwork.home.preview" android:resource="@drawable/example_watch_background" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.google.android.clockwork.home.category.HOME_BACKGROUND" />
</intent-filter>
</activity>
对于检测圆形布局,moto 360设备使用OnApply WindowInsetts或onReadyForContent,但存在相同的问题
知道吗,因为当我使用这个类别时,com.google.android.clockwork.home.category.home\u BACKGROUND不起作用
谢谢在新的Android smartwatch SDK实现之前,您不能在自定义手表表面上使用SetOnApplyWindowInsertsListener/OnApplyWindowInserts。此功能仅适用于没有外接程序清单的smartwatch应用程序 要了解钟面是否为圆形,可以使用:
public static boolean heightSameAsWidth(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels;
return height == width;
}
private void checkIfWatchIsRound() {
if (heightSameAsWidth(getApplicationContext())) {
isRound = false;
} else {
isRound = true;
}
}
有了新的SDK,您需要像上所示那样进行操作
在这里,正如您所看到的,您还可以获得底部屏幕间隙值,例如Moto 360。您可以发布整个清单吗?这在华为手表上不起作用,因为华为手表的高度=宽度
private class Engine extends CanvasWatchFaceService.Engine {
boolean mIsRound;
int mChinSize;
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
mIsRound = insets.isRound();
mChinSize = insets.getSystemWindowInsetBottom();
}
...
}