android 安装成功回掉,android – OnLocationChanged回调从未调用

我想使用LocationManager获取用户的当前位置。我做了很多研究,似乎找不到任何人有同样的问题。 OnLocationChanged回调似乎从未被调用。下面是我的各种代码和logcat。

protected LocationListener locationListener;

protected LocationManager locationManager;

protected Context context;

My OnCreate()方法

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

Log.v(TAG, "IN ON CREATE");

this.context = getActivity();

registerLocationUpdates();

}

我的registerLocationUpdates方法

void registerLocationUpdates() {

Criteria criteria = new Criteria();

criteria.setAccuracy(Criteria.ACCURACY_LOW);

criteria.setPowerRequirement(Criteria.POWER_LOW);

criteria.setAltitudeRequired(false);

criteria.setBearingRequired(false);

locationManager = (LocationManager)getActivity().getSystemService(LOCATION_SERVICE);

provider = locationManager.getBestProvider(criteria, true);

// Cant get a hold of provider

if (provider == null) {

Log.v(TAG, "Provider is null");

showNoProvider();

return;

} else {

Log.v(TAG, "Provider: " + provider);

}

locationListener = new MyLocationListener();

locationManager.requestLocationUpdates(provider, 1L, 1f, locationListener);

// connect to the GPS location service

Location oldLocation = locationManager.getLastKnownLocation(provider);

if (oldLocation != null) {

Log.v(TAG, "Got Old location");

latitude = Double.toString(oldLocation.getLatitude());

longitude = Double.toString(oldLocation.getLongitude());

waitingForLocationUpdate = false;

getNearbyStores();

} else {

Log.v(TAG, "NO Last Location found");

}

}

我的位置监听器

private class MyLocationListener implements LocationListener {

public void onLocationChanged(Location location) {

latitude = Double.toString(location.getLatitude());

longitude = Double.toString(location.getLongitude());

Log.v(TAG, "IN ON LOCATION CHANGE");

if (waitingForLocationUpdate) {

getNearbyStores();

waitingForLocationUpdate = false;

}

locationManager.removeUpdates(this);

}

public void onStatusChanged(String s, int i, Bundle bundle) {

Log.v(TAG, "Status changed: " + s);

}

public void onProviderEnabled(String s) {

Log.e(TAG, "PROVIDER DISABLED: " + s);

}

public void onProviderDisabled(String s) {

Log.e(TAG, "PROVIDER DISABLED: " + s);

}

}

我在AndroidManifest中的权限

最后是我运行我的应用程序后的logcat

01-25 09:43:10.963: VERBOSE/NearbyListFragment(3060): IN ON CREATE

01-25 09:43:10.963: VERBOSE/LocationManagerService(1329): getProviders

01-25 09:43:10.963: VERBOSE/LocationManagerService(1329): getProviders

01-25 09:43:10.973: VERBOSE/LocationManagerService(1329): getProviders

01-25 09:43:10.983: VERBOSE/NearbyListFragment(3060): Provider: gps

01-25 09:43:10.983: DEBUG/LocationManager(3060): requestLocationUpdates: provider = gps, listener = co.fusionweb.dealsplus.app.NearbyItems$NearbyListFragment$MyLocationListener@46ef4680

01-25 09:43:10.983: DEBUG/GpsLocationProvider(1329): setMinTime 1

01-25 09:43:10.983: VERBOSE/NearbyListFragment(3060): NO Last Location found

01-25 09:43:10.983: VERBOSE/LocationManagerService(1329): _requestLocationUpdates: listener = Receiver{47421e68 Listener android.os.BinderProxy@47421a68}

01-25 09:43:11.003: VERBOSE/countingFragment(3060): IN ON CREATE VIEW

01-25 09:43:11.003: WARN/GpsLocationProvider(1329): Duplicate add listener for co.fusionweb.dealsplus

01-25 09:43:11.013: VERBOSE/ScrollListener(3060): In Constructor

01-25 09:43:11.013: VERBOSE/ScrollListener(3060): Scrolling

01-25 09:43:11.033: DEBUG/GpsLocationProvider(1329): startNavigating

01-25 09:43:11.043: DEBUG/lib_locapi(1329): loc_eng_set_qos_time_out(standalone = 60, agps = 89)

01-25 09:43:11.043: DEBUG/lib_locapi(1329): loc_eng_set_qos_accuracy(accuracy = 50)

01-25 09:43:11.043: VERBOSE/lib_locapi(1329): persist.radio.agps.mode: []

01-25 09:43:11.043: DEBUG/lib_locapi(1329): loc_eng_set_position mode, client = 1, interval = 1, mode = 1

01-25 09:43:11.043: VERBOSE/lib_locapi(1329): loc_eng_ioctl called: client = 1, ioctl_type = 2

01-25 09:43:11.043: VERBOSE/locapi_rpc_glue(1329): loc_ioctl

01-25 09:43:11.043: DEBUG/RPC(1329): written RPC packet size: [96]

01-25 09:43:11.043: DEBUG/RPC(1329): read RPC packet

01-25 09:43:11.043: DEBUG/RPC(1329): read RPC packet size: [28]

01-25 09:43:11.043: VERBOSE/locapi_rpc_glue(1329): loc_api_sync_ioctl: select_id = 0, loc_ioctl returned 0

01-25 09:43:11.043: DEBUG/RPC(1329): read RPC packet

01-25 09:43:11.043: DEBUG/RPC(1329): read RPC packet size: [80]

01-25 09:43:11.043: VERBOSE/locapi_rpc_glue(1329): Callback received: 80 (cb_id=0x5310000 handle=1)

01-25 09:43:11.043: DEBUG/RPC(1329): written RPC packet size: [28]

01-25 09:43:11.043: VERBOSE/lib_locapi(1329): loc_eng_ioctl result: client = 1, ioctl_type = 2, SUCCESS

01-25 09:43:11.043: DEBUG/lib_locapi(1329): loc_eng_start

01-25 09:43:11.043: DEBUG/locapi_rpc_glue(1329): loc_start_fix

01-25 09:43:11.043: DEBUG/RPC(1329): written RPC packet size: [44]

01-25 09:43:11.043: DEBUG/RPC(1329): read RPC packet

01-25 09:43:11.053: DEBUG/RPC(1329): read RPC packet size: [28]

01-25 09:43:11.103: DEBUG/RPC(1329): read RPC packet

01-25 09:43:11.103: DEBUG/RPC(1329): read RPC packet size: [80]

01-25 09:43:11.113: VERBOSE/locapi_rpc_glue(1329): Callback received: 100 (cb_id=0x5310000 handle=1)

01-25 09:43:11.113: VERBOSE/lib_locapi(1329): process_deferred_action: pthread_cond_wait returned

01-25 09:43:11.113: DEBUG/lib_locapi(1329): loc_eng_report_status: GPS_STATUS_SESSION_BEGIN

01-25 09:43:11.113: DEBUG/lib_locapi(1329): loc_eng_report_status: update status

01-25 09:43:11.113: VERBOSE/GpsLocationProvider(1329): reportStatus status: 1

01-25 09:43:11.113: DEBUG/GpsLocationProvider(1329): Acquiring wakelock

01-25 09:43:11.123: DEBUG/RPC(1329): written RPC packet size: [28]

01-25 09:43:11.183: DEBUG/PowerManagerService(1329): New lightsensor value:40, lcdValue:77

01-25 09:43:11.273: DEBUG/RPC(1329): read RPC packet

01-25 09:43:11.273: DEBUG/RPC(1329): read RPC packet size: [80]

01-25 09:43:11.273: VERBOSE/locapi_rpc_glue(1329): Callback received: 100 (cb_id=0x5310000 handle=1)

01-25 09:43:11.273: VERBOSE/lib_locapi(1329): process_deferred_action: pthread_cond_wait returned

01-25 09:43:11.273: DEBUG/lib_locapi(1329): loc_eng_report_status: GPS_STATUS_ENGINE_ON

01-25 09:43:11.273: DEBUG/lib_locapi(1329): loc_eng_report_status: update status

01-25 09:43:11.273: VERBOSE/GpsLocationProvider(1329): reportStatus status: 3

和android SDK的位置部分的logcat保持重复他们自己。我试过一切,我可以想到和已经看到在谷歌和stackoverflow。 Als只是作为附注我已经能够得到它工作在2.3设备使用requestSingleUpdate它是可用在API 9和通过遵循指南A Deep Dive into Location,但我需要它工作在2.1或2.2和更高使用旧的SDK 。 SO如果你有任何提示或想知道更多,请让我知道。提前致谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值