今天调试一个荣耀平板闪退,结果发现设备没有GPS定位芯片,导致闪退。研究一番,可通过以下代码检测设备是否有GPS硬件模块:
public boolean hasGPSDevice(Context context)
{
final LocationManager mgr = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
if ( mgr == null )
return false;
final List<String> providers = mgr.getAllProviders();
if ( providers == null )
return false;
return providers.contains(LocationManager.GPS_PROVIDER);
}
在非华为设备中以下代码也可以,但是华为的鸿蒙系统中就不行:
if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
MyLog.e("错误:", "设备缺少GPS模块!");
}
本文讲述了作者在调试荣耀平板时遇到的闪退问题,原因是设备缺少GPS定位芯片。提供了一段代码示例用于检测GPS硬件模块,并指出在华为鸿蒙系统中的特殊情况。
2343

被折叠的 条评论
为什么被折叠?



