0

我使用广播接收器在我的应用程序中获取我的当前位置。它在我的手机上运行良好(返回当前位置值)。但是,当我使用平板电脑时,它返回零值。对于我的标签版本,我使用的是 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 中不起作用。碎片有问题吗??

有什么解决方案吗?

4

0 回答 0