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

The following examples show how to use android.location.Location#setElapsedRealtimeNanos() . 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: LocationProvider.java    From privatelocation with GNU General Public License v3.0 7 votes vote down vote up
void pushLocation(double lat, double lon) {
    LocationManager locationManager = (LocationManager) context.getSystemService(
            Context.LOCATION_SERVICE);

    Location mockLocation = new Location(providerName);
    mockLocation.setLatitude(lat);
    mockLocation.setLongitude(lon);
    mockLocation.setAltitude(3F);
    mockLocation.setTime(System.currentTimeMillis());
    mockLocation.setSpeed(0.01F);
    mockLocation.setBearing(1F);
    mockLocation.setAccuracy(3F);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mockLocation.setBearingAccuracyDegrees(0.1F);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mockLocation.setVerticalAccuracyMeters(0.1F);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mockLocation.setSpeedAccuracyMetersPerSecond(0.01F);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    }
    locationManager.setTestProviderLocation(providerName, mockLocation);
}
 
Example 2
Source File: LocationFactory.java    From io.appium.settings with Apache License 2.0 6 votes vote down vote up
public synchronized Location createLocation(String providerName, float accuracy) {
    Location l = new Location(providerName);
    l.setAccuracy(accuracy);

    l.setLatitude(latitude);
    l.setLongitude(longitude);
    l.setAltitude(altitude);
    l.setSpeed(0);
    l.setBearing(0);

    l.setTime(System.currentTimeMillis());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        l.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    }
    return l;
}
 
Example 3
Source File: LocationHooker.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public Object onInvoke(Object originObject, Object proxyObject, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
    if (!GpsMockManager.getInstance().isMocking()) {
        return method.invoke(originObject, args);
    }
    Location lastKnownLocation = (Location) method.invoke(originObject, args);
    if (lastKnownLocation == null) {
        String provider = (String) args[0].getClass().getDeclaredMethod("getProvider").invoke(args[0]);
        lastKnownLocation = buildValidLocation(provider);
    }
    lastKnownLocation.setLongitude(GpsMockManager.getInstance().getLongitude());
    lastKnownLocation.setLatitude(GpsMockManager.getInstance().getLatitude());
    lastKnownLocation.setTime(System.currentTimeMillis());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        lastKnownLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    }
    return lastKnownLocation;
}
 
Example 4
Source File: LocationHooker.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public Object onInvoke(Object originObject, Object proxyObject, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
    if (!GpsMockManager.getInstance().isMocking()) {
        return method.invoke(originObject, args);
    }
    Location lastLocation = (Location) method.invoke(originObject, args);
    if (lastLocation == null) {
        lastLocation = buildValidLocation(null);
    }
    lastLocation.setLongitude(GpsMockManager.getInstance().getLongitude());
    lastLocation.setLatitude(GpsMockManager.getInstance().getLatitude());
    lastLocation.setTime(System.currentTimeMillis());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        lastLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    }
    return lastLocation;
}
 
Example 5
Source File: LocationHooker.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
private static Location buildValidLocation(String provider) {
    if (TextUtils.isEmpty(provider)) {
        provider = "gps";
    }
    Location validLocation = new Location(provider);
    validLocation.setAccuracy(5.36f);
    validLocation.setBearing(315.0f);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        validLocation.setBearingAccuracyDegrees(52.285362f);
    }
    validLocation.setSpeed(0.79f);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        validLocation.setSpeedAccuracyMetersPerSecond(0.9462558f);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        validLocation.setVerticalAccuracyMeters(8.0f);
    }
    validLocation.setTime(System.currentTimeMillis());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        validLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    }
    return validLocation;
}
 
Example 6
Source File: BackgroundLocation.java    From background-geolocation-android with Apache License 2.0 6 votes vote down vote up
/**
 * Return android Location instance
 *
 * @return android.location.Location instance
 */
public Location getLocation() {
    Location l = new Location(provider);
    l.setLatitude(latitude);
    l.setLongitude(longitude);
    l.setTime(time);
    if (hasAccuracy) l.setAccuracy(accuracy);
    if (hasAltitude) l.setAltitude(altitude);
    if (hasSpeed) l.setSpeed(speed);
    if (hasBearing) l.setBearing(bearing);
    l.setExtras(extras);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        l.setElapsedRealtimeNanos(elapsedRealtimeNanos);
    }

    return l;
}
 
Example 7
Source File: MainActivity.java    From together-go with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void setLocation(double longtitude, double latitude) {

        // 因为我是在北京的,我把这个海拔设置了一个符合北京的范围,随机生成
        altitude = genDouble(38.0, 50.5);
        // 而定位有精度,GPS精度一般小于15米,我设置在1到15米之间随机
        accuracy = (float)genDouble(1.0, 15.0);

        // 下面就是自己设置定位的位置了
        Location location = new Location(LocationManager.GPS_PROVIDER);
        location.setTime(System.currentTimeMillis());
        location.setLatitude(latitude);
        location.setLongitude(longtitude);
        // 北京海拔大概范围,随机生成
        location.setAltitude(altitude);
        // GPS定位精度范围,随机生成
        location.setAccuracy(accuracy);
        if (Build.VERSION.SDK_INT > 16) {
            location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
        }
        try {
            locationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, location);
        } catch (SecurityException e) {
            simulateLocationPermission();
        }
    }
 
Example 8
Source File: RfEmitter.java    From DejaVu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * User facing location value. Differs from internal one in that we don't report
 * locations that are guarded due to being new or moved.
 *
 * @return The coverage estimate for our RF emitter or null if we don't trust our
 * information.
 */
public  Location getLocation() {
    // If we have no observation of the emitter we ought not give a
    // position estimate based on it.
    if (mLastObservation == null)
        return null;

    // If we don't trust the location, we ought not give a position
    // estimate based on it.
    if ((trust < REQUIRED_TRUST) || (status == EmitterStatus.STATUS_BLACKLISTED))
        return null;

    // If we don't have a coverage estimate we will get back a null location
    Location location = _getLocation();
    if (location == null)
        return null;

    // If we are unbelievably close to null island, don't report location
    if (!BackendService.notNullIsland(location))
        return null;

    // Time tags based on time of most recent observation
    location.setTime(mLastObservation.getLastUpdateTimeMs());
    location.setElapsedRealtimeNanos(mLastObservation.getElapsedRealtimeNanos());

    Bundle extras = new Bundle();
    extras.putString(LOC_RF_TYPE, type.toString());
    extras.putString(LOC_RF_ID, id);
    extras.putInt(LOC_ASU,mLastObservation.getAsu());
    extras.putLong(LOC_MIN_COUNT, ourCharacteristics.minCount);
    location.setExtras(extras);
    return location;
}
 
Example 9
Source File: NmeaParser.java    From UsbGps4Droid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Notifies a new location fix to the MockLocationProvider
 * @param fix the location
 * @throws SecurityException
 */
private void notifyFix(Location fix) throws SecurityException {
    fixTime = null;
    hasGGA = false;
    hasRMC = false;

    if (fix != null) {
        ((USBGpsApplication) appContext).notifyNewLocation(fix);
        log("New Fix: " + System.currentTimeMillis() + " " + fix);

        if (lm != null && mockGpsEnabled) {

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                fix.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
            }

            try {
                lm.setTestProviderLocation(mockLocationProvider, fix);

            } catch (IllegalArgumentException e) {
                log("Tried to notify a fix that was incomplete");
                log("Accuracy = " + Float.toString(fix.getAccuracy()));

            }
            log("New Fix notified to Location Manager: " + mockLocationProvider);

        } else {
            log("Fix could not be notified, no locationManager");

        }
        this.fix = null;
    }
}
 
Example 10
Source File: MockWalk.java    From AndroidProgramming3e with Apache License 2.0 5 votes vote down vote up
private void postNextLocation() {
    int nextIndex = (mCurrentLocationIndex + 1) % mLocations.size();

    Location nextLocation = new Location(mLocations.get(nextIndex));
    nextLocation.setTime(System.currentTimeMillis());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        nextLocation.setElapsedRealtimeNanos(System.nanoTime());
    }

    LocationServices.FusedLocationApi
            .setMockLocation(mClient, nextLocation);

    Log.i(TAG, "New location: " + nextLocation);
    mCurrentLocationIndex = nextIndex;
}
 
Example 11
Source File: GpsMocker.java    From AutoInteraction-Library with Apache License 2.0 5 votes vote down vote up
private void scheduleMockGps(final Context context) {
    Gps gps;
    synchronized (mMockGps) {
        gps = mMockGps[0];
    }
    if (null == gps) {
        return;
    }
    if (!Macro.RealGps) {
        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        Location location = new Location(LocationManager.GPS_PROVIDER);
        location.setLatitude(gps.mLatitude);
        location.setLongitude(gps.mLongitude);
        location.setAltitude(0);
        location.setBearing(0);
        location.setSpeed(0);
        location.setAccuracy(2);
        location.setTime(System.currentTimeMillis());
        location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
        locationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, location);
    }
    new Handler(context.getMainLooper()).postDelayed(new Runnable() {
        @Override
        public void run() {
            scheduleMockGps(context);
        }
    }, 1000);
}
 
Example 12
Source File: MockLocationProvider.java    From android_coursera_1 with MIT License 5 votes vote down vote up
public void pushLocation(double lat, double lon) {

		Location mockLocation = new Location(mProviderName);
		mockLocation.setLatitude(lat);
		mockLocation.setLongitude(lon);
		mockLocation.setAltitude(0);
		mockLocation.setTime(System.currentTimeMillis());
		mockLocation
				.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
		mockLocation.setAccuracy(mockAccuracy);

		mLocationManager.setTestProviderLocation(mProviderName, mockLocation);

	}
 
Example 13
Source File: Kalman.java    From DejaVu with GNU General Public License v3.0 5 votes vote down vote up
public synchronized Location getLocation() {
    Long timeMs = System.currentTimeMillis();
    final Location location = new Location(BackendService.LOCATION_PROVIDER);

    predict(timeMs);
    location.setTime(timeMs);
    location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    location.setLatitude(mLatTracker.getPosition());
    location.setLongitude(mLonTracker.getPosition());
    if (mAltTracker != null)
        location.setAltitude(mAltTracker.getPosition());

    float accuracy = (float) (mLatTracker.getAccuracy() * BackendService.DEG_TO_METER);
    if (accuracy < MIN_ACCURACY)
        accuracy = MIN_ACCURACY;
    location.setAccuracy(accuracy);

    // Derive speed from degrees/ms in lat and lon
    double latVeolocity = mLatTracker.getVelocity() * BackendService.DEG_TO_METER;
    double lonVeolocity = mLonTracker.getVelocity() * BackendService.DEG_TO_METER *
            Math.cos(Math.toRadians(location.getLatitude()));
    float speed = (float) Math.sqrt((latVeolocity*latVeolocity)+(lonVeolocity*lonVeolocity));
    location.setSpeed(speed);

    // Compute bearing only if we are moving. Report old bearing
    // if we are below our threshold for moving.
    if (speed > MOVING_THRESHOLD) {
        mBearing = (float) Math.toDegrees(Math.atan2(latVeolocity, lonVeolocity));
    }
    location.setBearing(mBearing);

    Bundle extras = new Bundle();
    extras.putLong("AVERAGED_OF", samples);
    location.setExtras(extras);

    return location;
}
 
Example 14
Source File: WeightedAverage.java    From DejaVu with GNU General Public License v3.0 5 votes vote down vote up
public Location result() {
    if (count < 1)
        return null;

    final Location location = new Location(BackendService.LOCATION_PROVIDER);

    location.setTime(timeMs);
    location.setElapsedRealtimeNanos(mElapsedRealtimeNanos);

    location.setLatitude(latEst.getMean());
    location.setLongitude(lonEst.getMean());

    //
    // Accuracy estimate is in degrees, convert to meters for output.
    // We calculate North-South and East-West independently, convert to a
    // circular radius by finding the length of the diagonal.
    //
    double sdMetersLat = latEst.getStdDev() * BackendService.DEG_TO_METER;
    double cosLat = Math.max(BackendService.MIN_COS, Math.cos(Math.toRadians(latEst.getMean())));
    double sdMetersLon = lonEst.getStdDev() * BackendService.DEG_TO_METER * cosLat;

    float acc = (float) Math.max(Math.sqrt((sdMetersLat*sdMetersLat)+(sdMetersLon*sdMetersLon)),MINIMUM_BELIEVABLE_ACCURACY);
    location.setAccuracy(acc);

    Bundle extras = new Bundle();
    extras.putLong("AVERAGED_OF", count);
    location.setExtras(extras);

    return location;
}
 
Example 15
Source File: MockLocationProvider.java    From FakeTraveler with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Pushes the location in the system (mock). This is where the magic gets done.
 *
 * @param lat latitude
 * @param lon longitude
 * @return Void
 */
public void pushLocation(double lat, double lon) {
    LocationManager lm = (LocationManager) ctx.getSystemService(
            Context.LOCATION_SERVICE);

    Location mockLocation = new Location(providerName);
    mockLocation.setLatitude(lat);
    mockLocation.setLongitude(lon);
    mockLocation.setAltitude(3F);
    mockLocation.setTime(System.currentTimeMillis());
    //mockLocation.setAccuracy(16F);
    mockLocation.setSpeed(0.01F);
    mockLocation.setBearing(1F);
    mockLocation.setAccuracy(3F);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mockLocation.setBearingAccuracyDegrees(0.1F);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mockLocation.setVerticalAccuracyMeters(0.1F);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mockLocation.setSpeedAccuracyMetersPerSecond(0.01F);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    }
    lm.setTestProviderLocation(providerName, mockLocation);
}
 
Example 16
Source File: LocationServiceTest.java    From background-geolocation-android with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 5000)
public void testOnLocationOnStoppedService() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(3);
    BroadcastReceiver serviceBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle bundle = intent.getExtras();
            int action = bundle.getInt("action");

            if (action == LocationServiceImpl.MSG_ON_SERVICE_STARTED) {
                latch.countDown();
                mService.stop();
                //mService.onDestroy();
            }
            if (action == LocationServiceImpl.MSG_ON_SERVICE_STOPPED) {
                latch.countDown();
                mService.onLocation(new BackgroundLocation());
            }
            if (action == LocationServiceImpl.MSG_ON_LOCATION) {
                latch.countDown();
            }
        }
    };

    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(InstrumentationRegistry.getTargetContext());
    lbm.registerReceiver(serviceBroadcastReceiver, new IntentFilter(LocationServiceImpl.ACTION_BROADCAST));

    Config config = Config.getDefault();
    config.setStartForeground(false);

    MockLocationProvider provider = new MockLocationProvider();
    Location location = new Location("gps");
    location.setProvider("mock");
    location.setElapsedRealtimeNanos(2000000000L);
    location.setAltitude(100);
    location.setLatitude(49);
    location.setLongitude(5);
    location.setAccuracy(105);
    location.setSpeed(50);
    location.setBearing(1);

    provider.setMockLocations(Arrays.asList(location));
    mLocationProviderFactory.setProvider(provider);

    mService.setLocationProviderFactory(mLocationProviderFactory);
    mService.configure(config);
    mService.start();

    latch.await();
    lbm.unregisterReceiver(serviceBroadcastReceiver);
}
 
Example 17
Source File: GnssLocationProvider.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void handleReportLocation(boolean hasLatLong, Location location) {
    if (location.hasSpeed()) {
        mItarSpeedLimitExceeded = location.getSpeed() > ITAR_SPEED_LIMIT_METERS_PER_SECOND;
    }

    if (mItarSpeedLimitExceeded) {
        Log.i(TAG, "Hal reported a speed in excess of ITAR limit." +
                "  GPS/GNSS Navigation output blocked.");
        if (mStarted) {
            mGnssMetrics.logReceivedLocationStatus(false);
        }
        return;  // No output of location allowed
    }

    if (VERBOSE) Log.v(TAG, "reportLocation " + location.toString());

    // It would be nice to push the elapsed real-time timestamp
    // further down the stack, but this is still useful
    location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    location.setExtras(mLocationExtras.getBundle());

    try {
        mILocationManager.reportLocation(location, false);
    } catch (RemoteException e) {
        Log.e(TAG, "RemoteException calling reportLocation");
    }

    if (mStarted) {
        mGnssMetrics.logReceivedLocationStatus(hasLatLong);
        if (hasLatLong) {
            if (location.hasAccuracy()) {
                mGnssMetrics.logPositionAccuracyMeters(location.getAccuracy());
            }
            if (mTimeToFirstFix > 0) {
                int timeBetweenFixes = (int) (SystemClock.elapsedRealtime() - mLastFixTime);
                mGnssMetrics.logMissedReports(mFixInterval, timeBetweenFixes);
            }
        }
    }

    mLastFixTime = SystemClock.elapsedRealtime();
    // report time to first fix
    if (mTimeToFirstFix == 0 && hasLatLong) {
        mTimeToFirstFix = (int) (mLastFixTime - mFixRequestTime);
        if (DEBUG) Log.d(TAG, "TTFF: " + mTimeToFirstFix);
        if (mStarted) {
            mGnssMetrics.logTimeToFirstFixMilliSecs(mTimeToFirstFix);
        }

        // notify status listeners
        mListenerHelper.onFirstFix(mTimeToFirstFix);
    }

    if (mSingleShot) {
        stopNavigating();
    }

    if (mStarted && mStatus != LocationProvider.AVAILABLE) {
        // For devices that use framework scheduling, a timer may be set to ensure we don't
        // spend too much power searching for a location, when the requested update rate is slow.
        // As we just recievied a location, we'll cancel that timer.
        if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mFixInterval < NO_FIX_TIMEOUT) {
            mAlarmManager.cancel(mTimeoutIntent);
        }

        // send an intent to notify that the GPS is receiving fixes.
        Intent intent = new Intent(LocationManager.GPS_FIX_CHANGE_ACTION);
        intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, true);
        mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
        updateStatus(LocationProvider.AVAILABLE);
    }

    if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mStarted &&
            mFixInterval > GPS_POLLING_THRESHOLD_INTERVAL) {
        if (DEBUG) Log.d(TAG, "got fix, hibernating");
        hibernate();
    }
}
 
Example 18
Source File: BackendHelper.java    From android_packages_apps_UnifiedNlp with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void updateElapsedRealtimeNanos(Location location) {
    if (location.getElapsedRealtimeNanos() <= 0) {
        location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    }
}
 
Example 19
Source File: LooperThread.java    From PocketMaps with MIT License 4 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {
    if (mMaxPredictTimeReached)
    {
      // Enqueue next prediction
      mOwnHandler.removeMessages(0);
      mOwnHandler.sendEmptyMessageDelayed(0, mMinTimeFilter);
      return true;
    }

    // Prepare location
    final Location location = new Location(KALMAN_PROVIDER);

    // Latitude
    mLatitudeTracker.predict(0.0);
    location.setLatitude(mLatitudeTracker.getPosition());

    // Longitude
    mLongitudeTracker.predict(0.0);
    location.setLongitude(mLongitudeTracker.getPosition());

    // Altitude
    if (mLastLocation.hasAltitude()) {

        mAltitudeTracker.predict(0.0);
        location.setAltitude(mAltitudeTracker.getPosition());
    }

    // Speed
    if (mLastLocation.hasSpeed())
        location.setSpeed(mLastLocation.getSpeed());

    // Bearing
    if (mLastLocation.hasBearing())
        location.setBearing(mLastLocation.getBearing());

    // Accuracy (always has)
    location.setAccuracy((float) (mLatitudeTracker.getAccuracy() * DEG_TO_METER));

    // Set times
    location.setTime(System.currentTimeMillis());

    if (Build.VERSION.SDK_INT >= 17)
        location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    
    if (mMaxPredictTime > 0)
    {
        long timeDiff = location.getTime() - mLastLocation.getTime();
        if (timeDiff > mMaxPredictTime) { mMaxPredictTimeReached = true; }
    }

    // Post the update in the client (UI) thread
    mClientHandler.post(new Runnable() {

        @Override
        public void run() {

            mClientLocationListener.onLocationChanged(location);
        }
    });

    // Enqueue next prediction
    mOwnHandler.removeMessages(0);
    mOwnHandler.sendEmptyMessageDelayed(0, mMinTimeFilter);
    mPredicted = true;

    return true;
}
 
Example 20
Source File: MockLocationGenerator.java    From test-samples with Apache License 2.0 3 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void pushLocation(Location mockLocation) {

    mockLocation.setTime(System.currentTimeMillis());
    mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());

    locationManager.setTestProviderLocation(mockLocation.getProvider(), mockLocation);

}