我有以下代码:
public class TrackingService extends Service implements LocationListener {
[...]
public static class TrackingStarter extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, TrackingService.class);
context.startService(i);
}
}
[...]
public int onStartCommand(Intent intent, int flags, int startId) {
[...]
LocationManager locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locmgr.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, this, null);
locmgr.requestSingleUpdate(LocationManager.GPS_PROVIDER, this, null);
[...]
}
@Override
public void onLocationChanged(Location location) {
Log.i("AppTag", "Reporting a location");
reportNewLocation(location.getLongitude(), location.getLatitude(), location.getAltitude(), location.getProvider(), location.getAccuracy(), location.getSpeed(), location.getTime());
}
[...]
}
它通过系统广播(BOOT_COMPLETED或MY_PACKAGE_REPLACED或MY_PACKAGE_ADDED)开始,根据logcat输出工作。
我的问题是从未报告过某个位置。我也尝试过Looper.myLooper()...... 任何人都可以指导我做错了吗?
我是logcat我可以从onStartCommand看到一些调试输出,我可以看到它完全通过该方法运行。但收据从未被称为? (我等了大约10分钟)