android手动开启GPS
2016-02-18 00:00
471 查看
摘要: android,手动,GPS
<span style="white-space:pre"> </span>/**
* 监听GPS
*/
private void initGPS() {
LocationManager locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
// 判断GPS模块是否开启,如果没有则开启
if (!locationManager
.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
Toast.makeText(TrainDetailsActivity.this, "请打开GPS",
Toast.LENGTH_SHORT).show();
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("请打开GPS");
dialog.setPositiveButton("确定",
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.setNeutralButton("取消", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
}
} );
dialog.show();
} else {
// 弹出Toast
// Toast.makeText(TrainDetailsActivity.this, "GPS is ready",
// Toast.LENGTH_LONG).show();
// // 弹出对话框
// new AlertDialog.Builder(this).setMessage("GPS is ready")
// .setPositiveButton("OK", null).show();
}
}
<span style="white-space:pre"> </span>/**
* 监听GPS
*/
private void initGPS() {
LocationManager locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
// 判断GPS模块是否开启,如果没有则开启
if (!locationManager
.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
Toast.makeText(TrainDetailsActivity.this, "请打开GPS",
Toast.LENGTH_SHORT).show();
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("请打开GPS");
dialog.setPositiveButton("确定",
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.setNeutralButton("取消", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
}
} );
dialog.show();
} else {
// 弹出Toast
// Toast.makeText(TrainDetailsActivity.this, "GPS is ready",
// Toast.LENGTH_LONG).show();
// // 弹出对话框
// new AlertDialog.Builder(this).setMessage("GPS is ready")
// .setPositiveButton("OK", null).show();
}
}
相关文章推荐
- Android反编译工具的使用--Android Killer
- 《Android源码设计模式》读书笔记 (12) 第12章 观察者模式
- Android事件分发机制完全解析,带你从源码的角度彻底理解(上)
- Activity生命周期的简单分析
- 源码解析Android中AsyncTask的工作原理
- Mac下Android Studio使用github
- Android 个人开发者接入支付功能
- Android 删除手机相册中的图片
- android:id="@id"与android:id="@+id/"的区别
- Android-- 输入法键盘控制
- android关于activity的组成
- android开机过程简单描述
- android截屏
- 从源代码分析Android-Universal-Image-Loader的缓存处理机制(强力推荐)
- Android命名规范
- 【Android】Android中关于Fragment使用的CheckList
- [Android Pro] Normal Permissions
- [Android Pro] Dangerous permissions and permission groups.
- Android Studio的开发视图中,顶部工具栏不见了如何设置回来
- Android中的动画