有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java本地化服务无法启动安卓

我正在开发一个安卓地图,并试图使用服务类查找用户的当前位置。我已经成功地完成了whitout服务(直接在主要活动中),但考虑到我将进行网络操作以查找地址和兴趣点,我认为尝试使用当前位置的服务是一种很好的培训

但问题是我的服务根本没有启动,即使我在清单中报告了它

扩展服务的我的类:

`

 package toutel.testcarte;

 import org.osmdroid.bonuspack.overlays.Marker;
 import org.osmdroid.util.GeoPoint;
 import org.osmdroid.views.MapController;
 import org.osmdroid.views.MapView;
 import 安卓.app.Service;
 import 安卓.content.Context;
 import 安卓.content.Intent;
 import 安卓.location.Location;
 import 安卓.location.LocationListener;
 import 安卓.location.LocationManager;
 import 安卓.os.Bundle;
 import 安卓.os.IBinder;

  public class FindMe extends Service {

private MapView mapView;
private MapController mapController;
private LocationManager lm;

private LocationListener mylocationlistener = new LocationListener() {

    public void onLocationChanged(Location location) {

        // Context ctx = getApplicationContext();
        GeoPoint myposition = new GeoPoint(location.getLatitude(),
                location.getLongitude());
        mapController.animateTo(myposition);
        mapController.setCenter(myposition);
        mapController.setZoom(17);
        Marker marker = new Marker(mapView);
        marker.setPosition(myposition);
        marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
        mapView.getOverlays().add(marker);
        mapView.invalidate();
        try {
            Thread.sleep(5 * 1000);
        }

        catch (InterruptedException e) {
            e.printStackTrace();
        }
        mapView.getOverlays().clear();

    }

    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

};

public IBinder onBind(Intent arg0) {

    return null;
}

public void onCreate(Bundle savedInstanceState) {

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0,
            mylocationlistener);
    lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0,
            mylocationlistener);
    super.onCreate();
}

public int onStartCommand(Intent intent, int flags, int startId) {

    return super.onStartCommand(intent, flags, startId);
}

public void onDestroy() {

    super.onDestroy();
    lm.removeUpdates(mylocationlistener);
}

} `

我正在使用启动主活动中的服务

startService(new Intent(MainActivity.this, FindMe.class));

我在清单中添加了服务:

<service 安卓:name = "toutel.testcarte.FindMe"> </service>

那么我做错了什么

谢谢


共 (0) 个答案