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

上一篇:Pymyaql操作数据库


下一篇:安装虚拟机&Linux命令学习