private void initGPS() {
LocationManager locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
// 判断GPS模块是否开启,如果没有则跳转至设置开启界面,设置完毕后返回到首页
if (!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("提醒:");
dialog.setMessage("为了更好的为您服务,请您打开您的GPS!");
dialog.setCancelable(false);
//界面上左边按钮,及其监听
dialog.setNeutralButton("确定",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// 转到手机设置界面,用户设置GPS
Intent intent = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 0); // 设置完成后返回到原来的界面
}
});
//界面上右边按钮,及其监听
dialog.setPositiveButton("取消", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
}
} );
dialog.show();
} else {
}
}
LocationManager locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
// 判断GPS模块是否开启,如果没有则跳转至设置开启界面,设置完毕后返回到首页
if (!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("提醒:");
dialog.setMessage("为了更好的为您服务,请您打开您的GPS!");
dialog.setCancelable(false);
//界面上左边按钮,及其监听
dialog.setNeutralButton("确定",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// 转到手机设置界面,用户设置GPS
Intent intent = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 0); // 设置完成后返回到原来的界面
}
});
//界面上右边按钮,及其监听
dialog.setPositiveButton("取消", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
}
} );
dialog.show();
} else {
}
}