2 GPS utility methods

时间:2023-03-09 00:10:26
2 GPS utility methods

Methond 1 is to check whether the GPS is on:

1
2
3
4
5
public boolean isGPSIsOn() {
LocationManager locationManager = (LocationManager) mContext
.getSystemService(Context.LOCATION_SERVICE);
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}

Method 2 is to open GPS setting page in Android device:

1
2
3
4
5
6
7
8
9
public void openGPSSettingPage() {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
context.startActivity(intent);
} catch (ActivityNotFoundException ex) {
}
}

Codes in Github : https://gist.github.com/Viyu/9406327