Android中定位功能的判断与打开

1.判断定位是否打开

public static boolean getGpsStatus(Context ctx){
    //从系统服务中获取定位管理器
    LocationManager lm = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
    return lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
}

2.跳转到打开定位的界面

public static void goToOpenGps(Context ctx){
    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    ctx.startActivity(intent);
}

猜你喜欢

转载自blog.csdn.net/weixin_38322371/article/details/115327148