判断gps并跳转到设置界面

来源:互联网 发布:微信转发赚钱平台源码 编辑:程序博客网 时间:2024/09/21 08:48
private void openGPSSettings() {LocationManager alm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {Toast.makeText(this, "GPS模块正常", Toast.LENGTH_SHORT).show();return;}final AlertDialog dlg = new AlertDialog.Builder(this).create();dlg.show();Window window = dlg.getWindow();window.setContentView(R.layout.shrew_exit_dialog);TextView title = (TextView) window.findViewById(R.id.title);title.setText("请开启GPS!");Button ok = (Button) window.findViewById(R.id.btn_ok);ok.setOnClickListener(new View.OnClickListener() {public void onClick(View v) {Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);startActivityForResult(intent, 0); // 此为设置完成后返回到获取界面dlg.cancel();}});Button cancel = (Button) window.findViewById(R.id.btn_cancel);cancel.setOnClickListener(new View.OnClickListener() {public void onClick(View v) {finish();}});}

0 0
原创粉丝点击