Flutter中如何检测华为设备并与其他Android设备区分?
华为设备识别与App Gallery更新引导实现方案
1. 华为设备识别逻辑
识别逻辑同时校验两个维度,准确率可达99%以上,兼容EMUI、HarmonyOS兼容Android层的所有华为/荣耀设备:
- 校验设备制造商信息为HUAWEI
- 校验系统存在EMUI/HarmonyOS专属属性
ro.build.version.emui
原生Android实现代码
import android.os.Build; import java.lang.reflect.Method; public static boolean isHuaweiDevice() { // 先判断制造商 if ("HUAWEI".equalsIgnoreCase(Build.MANUFACTURER)) { return true; } // 兼容部分未标记制造商的HarmonyOS设备,反射读取系统属性 try { Class<?> systemProperties = Class.forName("android.os.SystemProperties"); Method getMethod = systemProperties.getMethod("get", String.class); String emuiVersion = (String) getMethod.invoke(null, "ro.build.version.emui"); return emuiVersion != null && !emuiVersion.trim().isEmpty(); } catch (Exception e) { return false; } }
跨平台框架实现
Flutter(基于device_info_plus包)
import 'package:device_info_plus/device_info_plus.dart'; Future<bool> isHuaweiDevice() async { final AndroidDeviceInfo androidInfo = await DeviceInfoPlugin().androidInfo; // 优先判断制造商 if (androidInfo.manufacturer.toLowerCase() == 'huawei') { return true; } // 校验EMUI专属属性 try { final emuiVer = androidInfo.systemProperties['ro.build.version.emui']; return emuiVer?.isNotEmpty ?? false; } catch (e) { return false; } }
React Native(基于react-native-device-info包)
import DeviceInfo from 'react-native-device-info'; const isHuaweiDevice = async () => { const manufacturer = await DeviceInfo.getManufacturer(); if (manufacturer.toLowerCase() === 'huawei') return true; // 可配合读取系统属性扩展判断,逻辑和原生一致 return false; }
2. 跳转App Gallery更新逻辑
识别到华为设备后,优先直接调起App Gallery客户端的应用详情页,避免跳转浏览器:
原生Android实现代码
import android.content.Context; import android.content.Intent; import android.net.Uri; import android.widget.Toast; public void jumpToAppGallery(Context context, String yourAppPackageName) { try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("appmarket://details?id=" + yourAppPackageName)); intent.setPackage("com.huawei.appmarket"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } catch (Exception e) { // 极少数设备未安装App Gallery的降级提示 Toast.makeText(context, "请安装华为应用市场后更新", Toast.LENGTH_SHORT).show(); } }
跨平台框架实现
用对应平台的跳转工具类直接拉起appmarket://details?id=你的应用包名即可:
- Flutter使用
url_launcher包调用launchUrl(Uri.parse("appmarket://details?id=你的应用包名")) - React Native使用
Linking.openURL("appmarket://details?id=你的应用包名")
3. 业务逻辑配合
- 后端可以分别维护Google Play、App Gallery两个渠道的最新版本号、强制更新标记
- 检测为华为设备时,拉取App Gallery对应的版本配置做比对,低于最新版本时触发强制更新弹窗,引导跳转App Gallery
- 非华为设备保持原有Google Play跳转逻辑不变
内容的提问来源于stack exchange,提问作者Muhamad Haydar Jawad
相关产品推荐
相关产品推荐

