'''
//判定是否使用了模拟定位
if(isSelectedMoniLocal(this)){
Intent intent = new Intent(
Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
startActivityForResult(intent, 0x0000101);
}
'''
/**
* 6.0以上系统判定是否允许当前应用使用模拟定位
* true--允许
* false--禁止
* @param mContext
* @return
*/
public static boolean isSelectedCurApp(Context mContext){
boolean statue=true;
String serviceName = Context.LOCATION_SERVICE;
locationManager = (LocationManager) mContext.getSystemService(serviceName);
try {
String providerStr = LocationManager.GPS_PROVIDER;
LocationProvider provider = locationManager.getProvider(providerStr);
if (provider != null) {
locationManager.addTestProvider(
provider.getName()
, provider.requiresNetwork()
, provider.requiresSatellite()
, provider.requiresCell()
, provider.hasMonetaryCost()
, provider.supportsAltitude()
, provider.supportsSpeed()
, provider.supportsBearing()
, provider.getPowerRequirement()
, provider.getAccuracy());
} else {
locationManager.addTestProvider(
providerStr
, true, true, false, false, true, true, true
, Criteria.POWER_HIGH, Criteria.ACCURACY_FINE);
}
} catch (SecurityException e) {
//如果没有选择当前的应用,则addTestProvider会抛出异常
statue= false;
}
return statue;
}
public static boolean isSelectedMoniLocal(Context mContext){
boolean status=false;
if(Build.VERSION.SDK_INT > 22){
//6.0以上版本
if(isSelectedCurApp(mContext)){
ToastUtil.showMessage(mContext, "为保证位置精确性,请不要允许此应用使用模拟定位",
Toast.LENGTH_SHORT);
status=true;
}
}else{
if (getMockLocationStatus(mContext).equals("1")) {
ToastUtil.showMessage(mContext, "为保证位置精确性,请关闭【允许模拟位置】选项!",
Toast.LENGTH_SHORT);
status=true;
}
}
return status;
}