Test device: HUAWEI TABLET HUAWEI MRX-W09 Android 10 API29
Scenario: During the development of Android, some users reported that the UI display of tablet devices was abnormal. Through communication, it was found to be caused by the parallel world of Hongmeng system.
Check for cloud: Check for cloud by checking for the existence of the SystemCapability class (starting with API5)
public static boolean isHarmonyOs(a){
try {
Class cls = Class.forName("ohos.utils.system.SystemCapability");
returncls! =null;
} catch (ClassNotFoundException e) {
e.printStackTrace();
return false; }}Copy the code
Turn on/off the parallel horizon of the relevant app on the Settings page
// Parallel horizon open:
2021-07-06 10:02:59.573 1644-1847/? D/HWMW_HwMagicWindowManagerService: setHwMagicWinEnabled, pkg = cn.firstleap.parent, enabled = true
2021-07-06 10:02:59.573 1644-1847/? D/HWMW_HwMagicWindowConfig: onAppSwitchChanged, pkg = cn.firstleap.parent, hwMagicWinEnabled = true
// Parallel horizon closed:
2021-07-06 10:03:35.929 1644-1848/? D/HWMW_HwMagicWindowManagerService: setHwMagicWinEnabled, pkg = cn.firstleap.parent, enabled = false
2021-07-06 10:03:35.929 1644-1848/? D/HWMW_HwMagicWindowConfig: onAppSwitchChanged, pkg = cn.firstleap.parent, hwMagicWinEnabled = false
Copy the code
Unable to find this API, give up;
Print the Configuration information:
// Parallel horizon closed: Configuration content:
{1.0? mcc? mnc [zh_CN_#Hans] ldltr sw640dp w1024dp h608dp 400dpi lrg hdr land finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0.0 - 2560.1600) mAppBounds=Rect(0.0 - 2560.1600) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_90} suim:1 fontWeightScale:100 s3.}
// Enable parallel horizon: Configuration content:
{1.0? mcc? mnc [zh_CN_#Hans] ldltr sw508dp w508dp h640dp 400dpi lrg hdr port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(644.0 - 1916.1600) mAppBounds=Rect(644.0 - 1916.1600) mWindowingMode=hw-magic-windows mDisplayWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0} suim:1 fontWeightScale:100 s6.}
Copy the code
It can be analyzed that: mWindowingMode is the normal condition of fullscreen; The hw-Magic-Windows parallel horizon is turned on. Code judgment:
/** ** Parallel horizon enabled ** /
public static boolean isHWMagicWindow(Context context) {
boolean hwMagicWindows = false;
try {
Resources res = context.getResources();
if(res ! =null) {
Configuration config = res.getConfiguration();
if(config ! =null) {
String con = config.toString();
if (con.contains("hw-magic-windows")) {
hwMagicWindows = true; }}}}catch (Exception e) {
e.printStackTrace();
}
Log.d(TAG, "hwMagicWindows:" + hwMagicWindows);
return hwMagicWindows;
}
Copy the code
After testing: Returns false if the portrait UI is displayed properly for the first time; Enter landscape UI display exception, return true; If an exception occurs on the portrait page, return false.
It can be concluded that this method is generally applicable to abnormal device prompts. It is still suggested to adapt, but the workload is a little heavy (especially without hongmeng API development experience) need to be familiar with Hongmeng API and related documents.
Parallel Horizon Thematic Multi-window Interaction – Parallel Horizon HONGmeng API