LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
if (!locationManager
.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
Intent gpsIntent = new Intent();
gpsIntent.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
gpsIntent.addCategory("android.intent.category.ALTERNATIVE");
gpsIntent.setData(Uri.parse("custom:3"));
try {
PendingIntent.getBroadcast(this, 0, gpsIntent, 0).send();
}
catch (CanceledException e) {
e.printStackTrace();
}
要加入<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>权限
if (!locationManager
.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
Intent gpsIntent = new Intent();
gpsIntent.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
gpsIntent.addCategory("android.intent.category.ALTERNATIVE");
gpsIntent.setData(Uri.parse("custom:3"));
try {
PendingIntent.getBroadcast(this, 0, gpsIntent, 0).send();
}
catch (CanceledException e) {
e.printStackTrace();
}
要加入<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>权限
本文介绍了如何使用Android的LocationManager来获取位置服务,并检查GPS提供者是否可用。若GPS未启用,将触发设置意图以引导用户打开GPS设置。
4038

被折叠的 条评论
为什么被折叠?



