showDialogGPSOpen(mainActivity.this);
//弹框判断GPS是否开启
private void showDialogGPSOpen(final Context context) {
View view = getLayoutInflater().inflate(R.layout.dialog_2, null);
//取消
final TextView cancel = (TextView) view.findViewById(R.id.cancel);
//确定
final TextView save = (TextView) view.findViewById(R.id.save);
final AlertDialog dialog = new AlertDialog.Builder(context)
.setView(view)
.create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(context, "系统检测到未开启GPS定位服务", Toast.LENGTH_LONG).show();
Intent intent=new Intent();
intent.setAction(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
});
}