我试图检测我的设备上的GPS是否打开。无法返回布尔值从GPS检查
目前,我只是返回一个布尔真或假的值,然后要么继续我的代码,要么引导用户到GPS设置。
当我返回布尔值时,我的代码崩溃了。我已经调试过它,但仍然无法看到它为什么会返回值。
下面是代码:
GPSYesOrNo g = new GPSYesOrNo(this);
check = g.checkStatus();
// check if GPS enabled
if (check == true) {
Intent Appoint = new Intent("com.example.flybaseapp.appointmantMenu");
startActivity(Appoint);
} else {
alert();
}
而且GPSYesOrNo类:
public class GPSYesOrNo {
Context cc;
private LocationManager locationManager;
boolean enable;
public GPSYesOrNo(Context c) {
this.cc = c;
checkStatus();
}
public boolean checkStatus() {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (enabled) {
return true;
} else {
return false;
}
}
}
任何人都可以看到,我错了?
邮政logcat的请。 – Egor 2013-03-11 20:52:49
@Egor Logcat添加了 – user1352057 2013-03-11 20:59:21
是否指定了'locationManager'?向我们展示代码。 – 323go 2013-03-11 21:00:43