我正在尝试检索LocationManager类的实例(以获取一些与GPS相关的信息)。我已经编写了一个简单的类来完成这个任务,但最终出现了错误。
Cannot make a static reference to the non-static method getSystemService(String) from the type Context
这是我的类
public class LocationManagerHelper {
static Location location = null;
public static Location getLocation () {
LocationManager manager = (LocationManager) Context.getSystemService(Context.LOCATION_SERVICE);
if(manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Location location = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
} else {
System.out.println("Provider is disabled");
}
return location;
}
}
谢谢。