检测android机器是否有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);
    }
复制代码

有些机器还真没有GPS模块。。。今天还真让我遇上了。

还是在程序里加入检测把,比如我的程序是强退了,用户体验太差了。。。

原文地址:https://www.cnblogs.com/riasky/p/3507389.html