Java Code Examples for android.location.Location#getProvider()

The following examples show how to use android.location.Location#getProvider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocationManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void handleLocationChanged(Location location, boolean passive) {
    // create a working copy of the incoming Location so that the service can modify it without
    // disturbing the caller's copy
    Location myLocation = new Location(location);
    String provider = myLocation.getProvider();

    // set "isFromMockProvider" bit if location came from a mock provider. we do not clear this
    // bit if location did not come from a mock provider because passive/fused providers can
    // forward locations from mock providers, and should not grant them legitimacy in doing so.
    if (!myLocation.isFromMockProvider() && isMockProvider(provider)) {
        myLocation.setIsFromMockProvider(true);
    }

    synchronized (mLock) {
        if (isAllowedByCurrentUserSettingsLocked(provider)) {
            if (!passive) {
                // notify passive provider of the new location
                mPassiveProvider.updateLocation(myLocation);
            }
            handleLocationChangedLocked(myLocation, passive);
        }
    }
}
 
Example 2
Source File: BackgroundLocation.java    From background-geolocation-android with Apache License 2.0 6 votes vote down vote up
public static BackgroundLocation fromLocation(Location location) {
    BackgroundLocation l = new BackgroundLocation();

    l.provider = location.getProvider();
    l.latitude = location.getLatitude();
    l.longitude = location.getLongitude();
    l.time = location.getTime();
    l.accuracy = location.getAccuracy();
    l.speed = location.getSpeed();
    l.bearing = location.getBearing();
    l.altitude = location.getAltitude();
    l.hasAccuracy = location.hasAccuracy();
    l.hasAltitude = location.hasAltitude();
    l.hasSpeed = location.hasSpeed();
    l.hasBearing = location.hasBearing();
    l.extras = location.getExtras();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        l.elapsedRealtimeNanos = location.getElapsedRealtimeNanos();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        l.setIsFromMockProvider(location.isFromMockProvider());
    }

    return l;
}
 
Example 3
Source File: LocationEntity.java    From background_location_updates with Apache License 2.0 6 votes vote down vote up
public static LocationEntity fromAndroidLocation(Location location) {
    Double vAcc = null, cAcc = null, speedAcc = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        vAcc = (double) location.getVerticalAccuracyMeters();
        cAcc = (double) location.getBearingAccuracyDegrees();
        speedAcc = (double) location.getSpeedAccuracyMetersPerSecond();
    }

    return new LocationEntity(
            (double) location.getAccuracy(),
            vAcc,
            location.getLongitude(),
            location.getLatitude(),
            location.getAltitude(),
            (double )location.getSpeed(),
            location.getTime(),
            0,
            (double) location.getBearing(),
            cAcc,
            speedAcc,
            location.getProvider()
    );
}
 
Example 4
Source File: CurrentLocationOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onLocationChanged(Location location) {
    boolean update;
    if (location != null) {
        String provider = location.getProvider();
        update = LocationUtil.isProviderEnabled(mContext, provider, false);

        if (update) {
            mCurrentLocation = location;
            mMapViewOverlays.postInvalidate();
        }

        if (mIsAutopanningEnabled) {
            if (mInitialLocation == null || mMapViewOverlays.isLockMap())
                mInitialLocation = location;

            if (mInitialLocation.distanceTo(location) >= getPanThreshold()) {
                if (mIsInScreenBounds) {
                    autopanTo(mInitialLocation, location);
                }

                mInitialLocation = location;
            }
        }
    }
}
 
Example 5
Source File: GpsMyLocationProvider.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onLocationChanged(final Location location) {
	if (mIgnorer==null) {
		Log.w(IMapView.LOGTAG, "GpsMyLocation provider, mIgnore is null, unexpected. Location update will be ignored");
		return;
	}
	if (location==null || location.getProvider()==null)
		return;
	// ignore temporary non-gps fix
	if (mIgnorer.shouldIgnore(location.getProvider(), System.currentTimeMillis()))
		return;

	mLocation = location;
	if (mMyLocationConsumer != null && mLocation !=null)
		mMyLocationConsumer.onLocationChanged(mLocation, this);
}
 
Example 6
Source File: PhoneUtils.java    From Mobilyzer with Apache License 2.0 5 votes vote down vote up
/** Returns the DeviceProperty needed to report the measurement result */
	public DeviceProperty getDeviceProperty(String requestApp) {
		String carrierName = telephonyManager.getNetworkOperatorName();
		Location location;
		if (isTestingServer(getServerUrl())) {
			location = getMockLocation();
		} else {
			location = getLocation();
		}
		//TODO Test on Veriozn and Sprint, as result may be unreliable on CDMA
		// networks (use getPhoneType() to determine if on a CDMA network)
		String networkCountryIso = telephonyManager.getNetworkCountryIso();

//		NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
		String networkType = PhoneUtils.getPhoneUtils().getNetwork();
		String ipConnectivity = "NOT SUPPORTED";
		String dnResolvability = "NOT SUPPORTED";
		Logger.w("IP connectivity is " + ipConnectivity);
		Logger.w("DN resolvability is " + dnResolvability);
//		if (activeNetwork != null) {
//			networkType = activeNetwork.getTypeName();
//		}
		String versionName = PhoneUtils.getPhoneUtils().getAppVersionName();
		PhoneUtils utils = PhoneUtils.getPhoneUtils();

		Logger.e("Request App is " + requestApp);
		Logger.e("Host apps:");
		for ( String app : PhoneUtils.clientKeySet ) {
			Logger.e(app);
		}
		String mobilyzerVersion = context.getString(R.string.scheduler_version_name);
		Logger.i("Scheduler version = " + mobilyzerVersion);
		return new DeviceProperty(getDeviceInfo().deviceId, versionName,
				System.currentTimeMillis() * 1000, getVersionStr(), ipConnectivity,
				dnResolvability, location.getLongitude(), location.getLatitude(), 
				location.getProvider(), networkType, carrierName, networkCountryIso,
				utils.getCurrentBatteryLevel(), utils.isCharging(), 
				utils.getCellInfo(false), getCellRssi(), getWifiRSSI(), getWifiSSID(), getWifiBSSID(), getWifiIpAddress(),
				mobilyzerVersion, PhoneUtils.clientKeySet, requestApp);
	}
 
Example 7
Source File: LocationStorage.java    From android-sdk with MIT License 5 votes vote down vote up
public static void save(Gson gson, SharedPreferences preferences, String key, Location location) {
    if (location != null) {
        LocationStorage storage = new LocationStorage(
                location.getProvider(), location.getLatitude(), location.getLongitude());
        preferences.edit().putString(key, gson.toJson(storage)).apply();
    }
}
 
Example 8
Source File: LocationManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Provides an interface to inject and set the last location if location is not available
 * currently.
 *
 * This helps in cases where the product (Cars for example) has saved the last known location
 * before powering off.  This interface lets the client inject the saved location while the GPS
 * chipset is getting its first fix, there by improving user experience.
 *
 * @param location - Location object to inject
 * @return true if update was successful, false if not
 */
@Override
public boolean injectLocation(Location location) {
    mContext.enforceCallingPermission(android.Manifest.permission.LOCATION_HARDWARE,
            "Location Hardware permission not granted to inject location");
    mContext.enforceCallingPermission(android.Manifest.permission.ACCESS_FINE_LOCATION,
            "Access Fine Location permission not granted to inject Location");

    if (location == null) {
        if (D) {
            Log.d(TAG, "injectLocation(): called with null location");
        }
        return false;
    }
    LocationProviderInterface p = null;
    String provider = location.getProvider();
    if (provider != null) {
        p = mProvidersByName.get(provider);
    }
    if (p == null) {
        if (D) {
            Log.d(TAG, "injectLocation(): unknown provider");
        }
        return false;
    }
    synchronized (mLock) {
        if (!isAllowedByCurrentUserSettingsLocked(provider)) {
            if (D) {
                Log.d(TAG, "Location disabled in Settings for current user:" + mCurrentUserId);
            }
            return false;
        } else {
            // NOTE: If last location is already available, location is not injected.  If
            // provider's normal source (like a GPS chipset) have already provided an output,
            // there is no need to inject this location.
            if (mLastLocation.get(provider) == null) {
                updateLastLocationLocked(location, provider);
            } else {
                if (D) {
                    Log.d(TAG, "injectLocation(): Location exists. Not updating");
                }
                return false;
            }
        }
    }
    return true;
}
 
Example 9
Source File: LegacyRequestMapper.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static boolean checkForCompleteGpsData(Location location) {
    return location != null && location.getProvider() != null && location.getTime() != 0;
}
 
Example 10
Source File: MainActivity.java    From mapbox-events-android with MIT License 4 votes vote down vote up
private static String getLocationText(Location location) {
  return location == null ? "Unknown location" :
    location.getProvider() + "(" + location.getLatitude() + ", " + location.getLongitude() + ")";
}
 
Example 11
Source File: BackgroundService.java    From BackPackTrackII with GNU General Public License v3.0 4 votes vote down vote up
private static String getProviderName(Location location, Context context) {
    String provider = (location == null ? context.getString(R.string.undefined) : location.getProvider());
    int resId = context.getResources().getIdentifier("provider_" + provider, "string", context.getPackageName());
    return (resId == 0 ? provider : context.getString(resId));
}