Wednesday, 21 August 2013

current location not working in android by using broadcastreceiver in tablet

current location not working in android by using broadcastreceiver in tablet

I used broadcastreceiver for getting my current location in my
application. It's working fine in my mobile(return current location
values). But, when I came to Tablet it returns zero values. For my tab
version I'm using Fragments concept. Here is my code of broadcastreceiver:
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;
}
}
Why this code not working in Tab. Is there any problem with Fragments??
Any solutions for this?

No comments:

Post a Comment