魅族不启动GPS,无法扫描WiFi信息

由于Android4.0以上不允许强制修改系统设置,所以要引导用于前往设置GPS功能启动。

启动GPS设置方法:

public static final int LOCATION_REQUEST = 110;

public static LocationManager openGPSSettings(final Context context){

    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
        DialogUtil.showDialog(context, "提示", "请先打开GPS开关", "确定", "取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                ((Activity)context).startActivityForResult(intent, LOCATION_REQUEST);
            }
        }, null);
    }
    return locationManager;
}

如何对是否打开做出响应呢:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == LOCATION_REQUEST){
        if (mLocationManager != null && mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
            loadWiFiList();
            wifiAdapter.notifyDataSetChanged();
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值