アプリケーションで現在の場所を取得するために、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;
}
}
このコードがタブで機能しない理由。フラグメントに問題はありますか??
これに対する解決策はありますか?