/**
 * 判断网络定位是否打开
 *
 * @return 定位打开结果
 */
public static boolean isLocationEnable(Activity activity) {
    LocationManager locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
    boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    return gps || network;
}

因为android 10 新增了在使用中允许的设定,隐私性是提高了,但是作为开发者就苦逼了,只要用户选了这个选项,以前的那些申请权限那些统统不管用,只能说让用户手动去开启权限了,

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐