我尝试连接位置服务而不使用位置设置,但是每次运行项目时都会出错。我提到了下面的代码
请告诉我如何在不导航到位置服务的情况下启用位置服务的示例代码。
这些是我写的logcat
public class Practice2 extends Activity implements LocationListener{
private static final String TAG = "Profile";
protected static final int REQUEST_CHECK_SETTINGS = 0x1;
protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
protected boolean gps_enabled,network_enabled;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.practice2);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, (android.location.LocationListener) this);
}
@Override
public void onLocationChanged(Location location) {
}
public void onProviderDisabled(String provider) {
Log.d("Latitude","disable");
}
public void onProviderEnabled(String provider) {
Log.d("Latitude","enable");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("Latitude","status");
}}
先谢谢
答案 0 :(得分:1)