通过在平板电脑中使用broadcastreceiver,当前位置无法在android中工作

时间:2013-08-22 05:58:38

标签: android android-fragments broadcastreceiver currentlocation

我使用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有问题吗?

任何解决方案吗?

0 个答案:

没有答案