我使用broadcastreceiver在我的应用程序中获取当前位置。它在我的手机中工作正常(返回当前位置值)。但是,当我来到Tablet时,它返回零值。对于我的标签版本,我正在使用Fragments概念。 这是我的广播接收者代码:
public class LocationBroadcastReceiver extends BroadcastReceiver{
private static LocationInfo M_USER_LOCATION_INFO;
@Override
public void onReceive(Context context, Intent intent) {
LocationInfo locationInfo = (LocationInfo) intent.getSerializableExtra(LocationLibraryConstants.LOCATION_BROADCAST_EXTRA_LOCATIONINFO);
refreshLocationIfChanged(locationInfo, context);
}
public static void refreshLocationIfChanged(LocationInfo locationInfo, Context context){
if(locationInfo == null){
locationInfo = new LocationInfo(context);
} else{
locationInfo.refresh(context);
}
if (locationInfo.anyLocationDataReceived()) {
M_USER_LOCATION_INFO = locationInfo;
}else{
LocationLibrary.forceLocationUpdate(context);
}
}
public static Location getCurrentLocation(){
Location location = new Location("currentLocation");
if(M_USER_LOCATION_INFO != null) {
location.setLatitude(M_USER_LOCATION_INFO.lastLat);
location.setLongitude(M_USER_LOCATION_INFO.lastLong);
}
return location;
}
}
为什么此代码无法在Tab中使用。 Fragments有问题吗?
任何解决方案吗?