6.0以上獲取位置信息,需要?jiǎng)討B(tài)申請(qǐng),這里討論當(dāng)位置權(quán)限申請(qǐng)同意了,但是位置信息關(guān)閉了(其實(shí)就是6.0以前的gps開關(guān))高精度定位也會(huì)獲取失敗?。ňW(wǎng)上有的檢測(cè)方法在某些手機(jī)上會(huì)檢測(cè)失敗,下列的方式親測(cè)有效)

位置信息開關(guān)
package com.guoshikeji.xiaoxiangDriver.utils;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
/**
* Created by tyl
* 2019/5/22/022
* Describe:
*/
public class GpsUtil {
/**
* 判斷GPS是否開啟,GPS或者AGPS開啟一個(gè)就認(rèn)為是開啟的
* @param context
* @return true 表示開啟
*/
public static final boolean isOPen(final Context context) {
if (context==null){
return true;
}
int locationMode = 0;
String locationProviders;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
return false;
}
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
} else {
locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders);
}
}
/**
* 跳轉(zhuǎn)設(shè)置 打開GPS
* @param context
*/
public static final void openGPS(Context context) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
context.startActivity(intent);
}
}