我正在使用 cwac-locpoll,它做得很好。但是,我的一些用户遇到了以下问题
java.lang.RuntimeException: WakeLock under-locked com.commonsware.cwac.locpoll.LocationPoller
at android.os.PowerManager$WakeLock.release(PowerManager.java:339)
at android.os.PowerManager$WakeLock.release(PowerManager.java:299)
at com.commonsware.cwac.locpoll.WakefulThread.onPostExecute(WakefulThread.java:59)
at com.commonsware.cwac.locpoll.LocationPollerService$PollerThread.onPostExecute(LocationPollerService.java:231)
at com.commonsware.cwac.locpoll.WakefulThread.run(WakefulThread.java:93)
这是我的LocationReceiver
课程,如您所见,它只是SharedPreferences
通过帮助程序类将获得的位置存储在我的应用程序中。
public class LocationReceiver extends BroadcastReceiver {
private static final String TAG = "LocationReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Bundle b = intent.getExtras();
Location loc = (Location) b.get(LocationPoller.EXTRA_LOCATION);
if (loc == null) {
loc = (Location) b.get(LocationPoller.EXTRA_LASTKNOWN);
if (loc == null) {
Log.w(TAG, "Unable to get location. " + intent.getStringExtra(LocationPoller.EXTRA_ERROR));
} else {
Log.w(TAG, "Timeout getting location, using previous one " + loc);
}
} else {
Log.i(TAG, "Got location " + loc);
}
// save location in preferences
if (loc != null) {
PrefsHelper.setLastLocation(loc.getLatitude(), loc.getLongitude());
}
}
}
我还使用了一个单独的 cwac-wakefulWakefulIntentService
来获取最后一个位置并做一些事情,但它们被设计为独立运行。换句话说:
LocationReceiver
由 cwac-locpoll 调用以不时地存储最后一个已知位置SharedPreferences
。- A
WakefulIntentService
(独立地)计划获取此位置并对其进行处理。
谢谢!