摘要:Android - 判斷是否有啟用GPS定位
import android.provider.Settings;
/**
* 回傳 目前有無開GPS的狀態
*/
@SuppressWarnings("deprecation")
public static boolean gpsStatus(final Activity activity,Boolean mDialog) {
boolean bLocOpen = false ;
try{
bLocOpen = Settings.System.getString(activity.getContentResolver(), Settings.System.LOCATION_PROVIDERS_ALLOWED).contains("gps") ;
}catch(NullPointerException e){
e.printStackTrace();
}
return bLocOpen;
}
開啟GPS設定頁面
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
activity.startActivity(intent);