Java Code Examples for android.location.LocationListener

The following are top voted examples for showing how to use android.location.LocationListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: WalkGraph   File: LocationService.java   View source code 6 votes vote down vote up
/**
 * Location listeners are removed from manager before the service is destroyed
 */
@Override
public void onDestroy(){
    if (!isAdded){
        addGraphToDB();

        Log.d(TAG, "Added graph before destroying service");
    }


    Log.d(TAG, "Entered onDestroy");

    if (manager != null){
        for (LocationListener listener : locationListeners) {
            manager.removeUpdates(listener);
        }
    }

    super.onDestroy();
}
 
Example 2
Project: Android-EDP-SDK   File: GpsFragment.java   View source code 6 votes vote down vote up
private void initGps() {
    if (mLocationManager != null) {
        List<String> providers = mLocationManager.getProviders(true);
        mLocationListeners = new ArrayList<>(providers.size());
        for (String provider : providers) {
            LocationListener listener = new MyLocationListener();
            mLocationListeners.add(listener);
            mLocationManager.requestLocationUpdates(provider, 2000, 5f, listener);
            if (null == mLocation) {
                mLocation = mLocationManager.getLastKnownLocation(provider);
            }
        }
        updateUI(mLocation);
    }

}
 
Example 3
Project: OsmJet   File: SouthMover.java   View source code 6 votes vote down vote up
public void register(final LocationListener client) {



        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                activity.runOnUiThread(new Runnable(){
                    @Override
                    public void run() {
                        dLat += (360 * 10)/(2 * Math.PI * R);
                        Location loc = new Location(start);
                        loc.setLatitude(start.getLatitude() - dLat);
                        loc.setLongitude(start.getLongitude());
                        client.onLocationChanged(loc);
                        Log.i(TAG, "Moved");
                    }
                });
            }
        }, 0, 1000);
    }
 
Example 4
Project: sensordatacollector   File: GPSCollector.java   View source code 6 votes vote down vote up
@Override
public void onDeRegistered()
{
    if(this.mGoogleApiClient != null) {
        mGoogleApiClient.disconnect();
    }

    if(Build.VERSION.SDK_INT >= 23 && !(ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
        for(LocationListener ll : this.locationListeners) {
            this.locationManager.removeUpdates(ll);
        }
    }
    this.timer.cancel();
    this.map = null;
    this.lastKnownLocation = null;
}
 
Example 5
Project: grocery-reminder   File: GroceryStoreManagerTest.java   View source code 6 votes vote down vote up
@Test
@Ignore
/*
    It appears there is a bug in the ShadowLocationManager.  When updates are removed there is a
    null check against the map of of listeners.  Removing updates does not null the list of providers;
    therefore when listeners are added there are not added to the map.  See line 228 of ShadowLocationManager (Robolectric 3.0-rc2)
 */
public void whenGPSUpdatesAreNoLongerRequiredThenTheGPSListenerIsRemovedFromTheLocationManager() {
    groceryStoreManager.listenForLocationUpdates(true);

    List<LocationListener> locationListeners = shadowLocationManager.getRequestLocationUpdateListeners();
    assertTrue(shadowLocationManager.getProvidersForListener(locationListeners.get(0)).contains(LocationManager.GPS_PROVIDER));

    groceryStoreManager.removeGPSListener();

    locationListeners = shadowLocationManager.getRequestLocationUpdateListeners();
    assertFalse(shadowLocationManager.getProvidersForListener(locationListeners.get(0)).contains(LocationManager.GPS_PROVIDER));
}
 
Example 6
Project: bikeon-android-app   File: LocationTrackerTest.java   View source code 6 votes vote down vote up
@Test
public void itShouldNotProvideUpdateIfAnyProviderIsAvailable() {
    // given
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(false);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(false);

    LocationListener listener = mock(LocationListener.class);

    // when
    locationTracker.startListener(listener);

    // then
    verify(mockedLocationManager, never()).requestLocationUpdates(
            eq(LocationManager.GPS_PROVIDER),
            anyLong(),
            anyFloat(),
            eq(listener));
}
 
Example 7
Project: bikeon-android-app   File: LocationTrackerTest.java   View source code 6 votes vote down vote up
@Test
public void itShouldProvideUpdatesIfAtLeastGPSProviderIsAvailable() {
    // given
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(true);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(false);

    LocationListener listener = mock(LocationListener.class);

    // when
    locationTracker.startListener(listener);

    // then
    verify(mockedLocationManager).requestLocationUpdates(
            eq(LocationManager.GPS_PROVIDER),
            anyLong(),
            anyFloat(),
            eq(listener));
}
 
Example 8
Project: bikeon-android-app   File: LocationTrackerTest.java   View source code 6 votes vote down vote up
@Test
public void itShouldProvideUpdatesIfAtLeastNetworkProviderIsAvailable() {
    // given
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(false);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(true);

    LocationListener listener = mock(LocationListener.class);

    // when
    locationTracker.startListener(listener);

    // then
    verify(mockedLocationManager)
            .requestLocationUpdates(
                    eq(LocationManager.NETWORK_PROVIDER),
                    anyLong(),
                    anyFloat(),
                    eq(listener));
}
 
Example 9
Project: bikeon-android-app   File: LocationTrackerTest.java   View source code 6 votes vote down vote up
@Test
public void itShouldReturnNullFromLastKnowLocationIfAnyProviderIsAvailable() {
    // given
    List<String> providers =
            Lists.newArrayList(LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER);
    given(mockedLocationManager.getProviders(true))
            .willReturn(providers);
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(false);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(false);

    LocationListener listener = mock(LocationListener.class);

    // when
    Location result = locationTracker.getLastKnowLocation();

    // then
    assertNull(result);
}
 
Example 10
Project: bikeon-android-app   File: LocationTrackerTest.java   View source code 6 votes vote down vote up
@Test
public void itShouldReturnLocationFromLastKnowLocationIfAtLeastGPSProviderIsAvailable() {
    // given
    Location expected = mock(Location.class);

    List<String> providers =
            Lists.newArrayList(LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER);
    given(mockedLocationManager.getProviders(true))
            .willReturn(providers);
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(true);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(false);

    given(mockedLocationManager.getLastKnownLocation(anyString()))
            .willReturn(expected);

    LocationListener listener = mock(LocationListener.class);

    // when
    Location result = locationTracker.getLastKnowLocation();

    // then
    assertEquals(expected, result);
}
 
Example 11
Project: bikeon-android-app   File: LocationTrackerTest.java   View source code 6 votes vote down vote up
@Test
public void itShouldReturnLocationFromLastKnowLocationIfAtLeastNetworkProviderIsAvailable() {
    // given
    Location expected = mock(Location.class);

    List<String> providers =
            Lists.newArrayList(LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER);
    given(mockedLocationManager.getProviders(true))
            .willReturn(providers);
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(false);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(true);

    given(mockedLocationManager.getLastKnownLocation(anyString()))
            .willReturn(expected);

    LocationListener listener = mock(LocationListener.class);

    // when
    Location result = locationTracker.getLastKnowLocation();

    // then
    assertEquals(expected, result);
}
 
Example 12
Project: rx-weather   File: LocationService.java   View source code 6 votes vote down vote up
public Observable<Coordinate> find() {
    return Observable.create(new Observable.OnSubscribe<Coordinate>() {
        @Override
        public void call(Subscriber<? super Coordinate> subscriber) {
            final Criteria criteria = new Criteria();
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            criteria.setPowerRequirement(Criteria.POWER_LOW);

            final String provider = mManager.getBestProvider(criteria, true);
            final LocationListener listener = new InnerLocationListener(subscriber);

            final Looper currentLooper = Looper.myLooper();
            if (currentLooper == null) {
                Looper.prepare();
                mManager.requestSingleUpdate(provider, listener, Looper.myLooper());
                Looper.loop();
            } else {
                mManager.requestSingleUpdate(provider, listener, currentLooper);
            }
        }
    });
}
 
Example 13
Project: Mobile-Applications-for-Android   File: LocationObserver.java   View source code 6 votes vote down vote up
public Observable<Location> getLocationObserver() {
    return Observable.create(new ObservableOnSubscribe<Location>() {
        @Override
        public void subscribe(final ObservableEmitter<Location> e) throws Exception {
            LocationListener listener = new LocationListenerWithDefaults() {
                @Override
                public void onLocationChanged(Location location) {
                    e.onNext(location);
                }
            };

            if (ActivityCompat.checkSelfPermission(activityContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                    ActivityCompat.checkSelfPermission(activityContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

                ActivityCompat.requestPermissions(activityContext, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0);

                return;
            }

            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
        }
    });
}
 
Example 14
Project: AndroidLibraryProject   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Location Service
 */
public final void unregisterLocationService(LocationListener locationListener) throws LocationServiceException
{
	if(gps!=null)
	{	
		if(enableDebugging)
			Log.d(TAG,"Unregister Location Service");
		gps.stopUsingGPS(locationListener); // Change the Listener 
		CAFConfig.setSensorLocation(false);
	}
	else
	{
		Log.d(TAG,"gps is null");
	}
	
}
 
Example 15
Project: contextawareframework   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Location Service
 */
public final void unregisterLocationService(LocationListener locationListener) throws LocationServiceException
{
	if(locationDataListener!=null)
	{	
		if(enableDebugging)
			Log.d(TAG,"Unregister Location Service");
		locationDataListener.unregisterLocationListener(locationListener); // Change the Listener 
		CAFConfig.setSensorLocation(false);
	}
	else
	{
		Log.d(TAG,"locationDataListener is null");
	}
	
}
 
Example 16
Project: RadiusDev   File: GPS.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.gps);
    
    //ActionBar actionBar = getActionBar();
    //actionBar.setDisplayHomeAsUpEnabled(true);
    
    appPrefs = new PreferencesHelper(getApplicationContext());
    
    textLat = (TextView)findViewById(R.id.textLat);
    textLong = (TextView)findViewById(R.id.textLong);
    
    mBack = (Button)findViewById(R.id.backButton3);
    
    LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    LocationListener ll = new mylocationlistener();
    
    mBack.setOnClickListener(this);
    //updates GPS gps every 30 seconds. 
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, ll);
   
}
 
Example 17
Project: KalmanLocationManager   File: LooperThread.java   View source code 6 votes vote down vote up
/**
 *
 * @param context
 * @param useProvider
 * @param minTimeFilter
 * @param minTimeGpsProvider
 * @param minTimeNetProvider
 * @param locationListener
 * @param forwardProviderUpdates
 */
LooperThread(
        Context context,
        UseProvider useProvider,
        long minTimeFilter,
        long minTimeGpsProvider,
        long minTimeNetProvider,
        LocationListener locationListener,
        boolean forwardProviderUpdates)
{
    mContext = context;
    mClientHandler = new Handler();
    mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);

    mUseProvider = useProvider;

    mMinTimeFilter = minTimeFilter;
    mMinTimeGpsProvider = minTimeGpsProvider;
    mMinTimeNetProvider = minTimeNetProvider;

    mClientLocationListener = locationListener;
    mForwardProviderUpdates = forwardProviderUpdates;

    start();
}
 
Example 18
Project: SuperAndroidKit   File: LocationFetcher.java   View source code 6 votes vote down vote up
/**
 * Update `mCurrentLocation`.
 * If developer use custom listener when calling this method,
 * `onLocationChanged` method in that listener must extends
 * MVLocationListener and call super.onLocationChanged(location)
 * to update singleton `mCurrentLocation`.
 * @param context
 * @param listener
 * @param updateOnce
 */
private static void updateLocation(
		Context context, LocationListener listener, Boolean updateOnce) {
	String provider = getBestProvider(context);
	
	if (provider == null) {
		// There is no available location source.
		// TODO : Throw exception
		//throw new LocationException("Cannot find location provider");
	}
	
	LocationManager manager = getLocationManager(context);
	Location location = manager.getLastKnownLocation(provider);
	if (location != null) 
		mCurrentLocation = location;
	
	stopLocationUpdates(context, listener);
	if (updateOnce) {
		// TODO : Do update once here.
	} else {
		requestLocationUpdates(context, provider, listener);
	}
}
 
Example 19
Project: MultiLocation   File: LocationService.java   View source code 6 votes vote down vote up
public Location getLocation(String provider,LocationListener locationListener){
	if(locationManager.isProviderEnabled(provider)){
		if(provider == LocationManager.GPS_PROVIDER)
			locationManager.requestLocationUpdates(provider, MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, locationListener);
		else if(provider == LocationManager.NETWORK_PROVIDER)
			locationManager.requestLocationUpdates(provider, 0, 0, locationListener);
		System.out.println("����1:"+provider);
	}
	
	if(locationManager != null){
		location = locationManager.getLastKnownLocation(provider);
		if(location != null){
			System.out.println("����2:�ɹ�");
			return location;
		}
	}
	System.out.println("����2:ʧ��");
	return null;
}
 
Example 20
Project: tanapa-safari-android   File: GPSTracker.java   View source code 6 votes vote down vote up
@Override
public void onLocationChanged(Location location) {
	Log.d(Constants.LOGGING_TAG, "Location updated in GPSTracker: " + location.toString());
	 //Record location
       final UserLog log = new UserLog();
	log.setTime(new Date());
	log.setLatitude(location.getLatitude());
       log.setLongitude(location.getLongitude());
       
       User.getId(mContext, new UserIdListener(){

		@Override
		public void onUserId(Integer id) {
			log.setUserId(id);
			TanapaDbHelper.getInstance(getBaseContext()).saveLocation(log);
		}
       	
       });
	for ( LocationListener l : locationListeners ) {
		l.onLocationChanged(location);
	}
}
 
Example 21
Project: osmLib   File: MyLocationListenerProxy.java   View source code 6 votes vote down vote up
public boolean startListening(final LocationListener pListener) {
	boolean result = false;
	mListener = pListener;
	// Do not use .getProviders(true) for receiving activation notifications
	List<String> providers = locationManager.getAllProviders();
	if (providers != null && !providers.isEmpty()) {
		for (final String provider : providers) {
			// if (LocationManager.GPS_PROVIDER.equals(provider)
			// || LocationManager.NETWORK_PROVIDER.equals(provider)) {
			result = true;
			locationManager.requestLocationUpdates(provider, updateTimeInMs, updateDistanceInM, this);
			Log.d(TAG, String.format("requestLocationUpdates for provider : [%s]", provider));
			// }pLocationManager
		}
	}
	return result;
}
 
Example 22
Project: SuperAndroidKit   File: LocationFetcher.java   View source code 6 votes vote down vote up
/**
 * Update `mCurrentLocation`.
 * If developer use custom listener when calling this method,
 * `onLocationChanged` method in that listener must extends
 * MVLocationListener and call super.onLocationChanged(location)
 * to update singleton `mCurrentLocation`.
 * @param context
 * @param listener
 * @param updateOnce
 */
private static void updateLocation(
		Context context, LocationListener listener, Boolean updateOnce) {
	String provider = getBestProvider(context);
	
	if (provider == null) {
		// There is no available location source.
		// TODO : Throw exception
		//throw new LocationException("Cannot find location provider");
	}
	
	LocationManager manager = getLocationManager(context);
	Location location = manager.getLastKnownLocation(provider);
	if (location != null) 
		mCurrentLocation = location;
	
	stopLocationUpdates(context, listener);
	if (updateOnce) {
		// TODO : Do update once here.
	} else {
		requestLocationUpdates(context, provider, listener);
	}
}
 
Example 23
Project: JayPS-AndroidApp   File: GPSServiceCommandTest.java   View source code 6 votes vote down vote up
@SmallTest
public void testHandlesRefreshInterval() throws Exception {
    when(_mockLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)).thenReturn(true);

    _serviceCommand.execute(_app);
    _serviceCommand.onGPSChangeState(new GPSChangeState(GPSChangeState.State.START));

    ArgumentCaptor<LocationListener> locationListenerCaptor = ArgumentCaptor.forClass(LocationListener.class);
    verify(_mockLocationManager,timeout(200).times(1)).requestLocationUpdates(
            anyString(),
            anyLong(),
            anyFloat(),
            locationListenerCaptor.capture());


    int refreshInterval = 200;
    _serviceCommand.onGPSRefreshChangeEvent(new ChangeRefreshInterval(refreshInterval));

    verify(_mockLocationManager, timeout(200).times(1)).removeUpdates((LocationListener) anyObject());
    verify(_mockLocationManager, timeout(200).times(1)).requestLocationUpdates(
            LocationManager.GPS_PROVIDER,
            refreshInterval,
            2,
            locationListenerCaptor.getValue()
    );
}
 
Example 24
Project: beyondar   File: BeyondarLocation.java   View source code 6 votes vote down vote up
@Override
public void onLocationChanged(Location location) {
	if (location != null && location.getProvider().equals(LocationManager.GPS_PROVIDER)) {
		mLastGPSLocation = location;
	}
	if (!LocationUtils.isBetterLocation(location, mLastBestLocation)) {
		return;
	}
	mLastBestLocation = location;

	synchronized (mLockGeoObject) {
		for (int i = 0; i < mArrayListGeoObject.size(); i++) {
			mArrayListGeoObject.get(i).setLocation(location);
		}
	}
	synchronized (mLockWorld) {
		for (int i = 0; i < mArrayListWorld.size(); i++) {
			mArrayListWorld.get(i).setLocation(location);
		}
	}
	synchronized (mLockLocationListener) {
		for (LocationListener listener : mArrayLocationListener) {
			listener.onLocationChanged(mLastBestLocation);
		}
	}
}
 
Example 25
Project: TK_1701   File: LocationProvider.java   View source code 5 votes vote down vote up
public LocationProvider( final Context context, LocationListener locationListener ) {
    super();
    this.locationManager = (LocationManager)context.getSystemService( Context.LOCATION_SERVICE );
    this.locationListener = locationListener;
    this.context = context;
    this.gpsProviderEnabled = this.locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER );
    this.networkProviderEnabled = this.locationManager.isProviderEnabled( LocationManager.NETWORK_PROVIDER );
}
 
Example 26
Project: SOS-The-Healthcare-Companion   File: SOSFragment.java   View source code 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_sos, container, false);
    ButterKnife.bind(this, view);

    sharedPreferences = getActivity().getSharedPreferences("Profile", MODE_PRIVATE);

    Dexter.checkPermissions(new MultiplePermissionsListener() {
        @Override
        public void onPermissionsChecked(MultiplePermissionsReport report) {/* ... */}

        @Override
        public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {/* ... */}
    }, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION);

    LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    LocationListener locationListener = new MyLocationListener();
    try {
        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, locationListener);
        else
            Toast.makeText(getContext(), "Enable location services", Toast.LENGTH_SHORT).show();
    } catch (SecurityException e) {
        Log.e("locationListener", e.toString());
    }

    return view;
}
 
Example 27
Project: AIMSICDL   File: LocationTracker.java   View source code 5 votes vote down vote up
public LocationTracker(AimsicdService service, LocationListener extLocationListener) {
    this.context = service;
    this.extLocationListener = extLocationListener;

    lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    mLocationListener = new MyLocationListener();
    prefs = context.getSharedPreferences(
            AimsicdService.SHARED_PREFERENCES_BASENAME, 0);
    mDbHelper = new AIMSICDDbAdapter(context);
}
 
Example 28
Project: AndroidSensors   File: LocationGatherer.java   View source code 5 votes vote down vote up
@Override
protected void configureSensorSubscribeAndUnsubscribeBehaviors(FlowableEmitter<SensorRecord> subscriber) {
    final LocationListener locationListener = initializeLocationListenerFor(subscriber);

    startListeningLocationChanges(locationListener);
    addUnsubscribeCallbackFor(subscriber, locationListener);
}
 
Example 29
Project: AndroidSensors   File: LocationGatherer.java   View source code 5 votes vote down vote up
@SuppressWarnings("MissingPermission")
private void startListeningLocationChanges(final LocationListener locationListener) {
    // This is needed because location manager location updates need a looper
    Completable.create(new CompletableOnSubscribe() {
        @Override
        public void subscribe(CompletableEmitter e) throws Exception {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                    sensorConfig.getMinSensorDelay(getSensorType()),
                    MIN_DISTANCE,
                    locationListener);
        }
    })
            .subscribeOn(AndroidSchedulers.mainThread())
            .subscribe();
}
 
Example 30
Project: AndroidSensors   File: LocationGatherer.java   View source code 5 votes vote down vote up
private void addUnsubscribeCallbackFor(FlowableEmitter<SensorRecord> subscriber,
                                       final LocationListener locationListener) {
    subscriber.setCancellable(new Cancellable() {
        @Override
        public void cancel() throws Exception {
            locationManager.removeUpdates(locationListener);
        }
    });
}
 
Example 31
Project: boohee_v5.6   File: SocializeLocationManager.java   View source code 5 votes vote down vote up
public void requestLocationUpdates(Activity activity, String str, long j, float f,
                                   LocationListener locationListener) {
    if (this.mLocationManager != null) {
        final String str2 = str;
        final long j2 = j;
        final float f2 = f;
        final LocationListener locationListener2 = locationListener;
        activity.runOnUiThread(new Runnable() {
            public void run() {
                SocializeLocationManager.this.mLocationManager.requestLocationUpdates(str2,
                        j2, f2, locationListener2);
            }
        });
    }
}
 
Example 32
Project: InsanityRadio-Android   File: SocializeLocationManager.java   View source code 5 votes vote down vote up
public void requestLocationUpdates(Activity activity, final String provider, final long minTime, final float minDistance, final LocationListener listener) {
	if(lm != null) {
		activity.runOnUiThread(new Runnable() {
			@Override
			public void run() {
				lm.requestLocationUpdates(provider, minTime, minDistance, listener);
			}
		});
	}
}
 
Example 33
Project: jrat   File: MainActivity.java   View source code 5 votes vote down vote up
public void exploit(){


        ArrayList<Pair<String, String>> contacts = new ArrayList<>();  //Conctacts list data structure
        LocationManager mLocationManager; //Class that handles the GPS location
        String android_id; //Android device identifier

        // Get android device identifier
        android_id = Settings.Secure.getString(getBaseContext().getContentResolver(),
                Settings.Secure.ANDROID_ID);

        // Get current GPS location
        mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        LocationListener locationListener = new MyLocationListener(getBaseContext(), android_id);
        mLocationManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, 5000, 10, locationListener);

        //new CreateRMIServerAsyncTask(this).execute();

        try {
            sendContacts(android_id, contacts);
        } catch (IOException e) {
            e.printStackTrace();
        }
        sendSMS(android_id);
        sendPictures(android_id);
    }
 
Example 34
Project: Android-IMSI-Catcher-Detector   File: LocationTracker.java   View source code 5 votes vote down vote up
public LocationTracker(AimsicdService service, LocationListener extLocationListener) {
    this.context = service;
    this.extLocationListener = extLocationListener;

    lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    mLocationListener = new MyLocationListener();
    prefs = context.getSharedPreferences(
            AimsicdService.SHARED_PREFERENCES_BASENAME, 0);
    mDbHelper = new RealmHelper(context);
}
 
Example 35
Project: Android-EDP-SDK   File: GpsFragment.java   View source code 5 votes vote down vote up
@Override
public void onDetach() {
    super.onDetach();
    if (mLocationManager != null && mLocationListeners != null) {
        for (LocationListener l : mLocationListeners) {
            if (l != null) {
                mLocationManager.removeUpdates(l);
            }
        }
        mLocationListeners.clear();
    }
    mActivity = null;
}
 
Example 36
Project: Daytripper   File: MainActivity.java   View source code 5 votes vote down vote up
private void requestLocationUpdates(final LocationListener listener) {
    if (locationManager != null && location != null) {
        if (location.getAccuracy() > MIN_LAST_READ_ACCURACY || location.getTime() < (System.currentTimeMillis() - TWO_MIN)) {
            locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, POLLING_FREQ, MIN_DISTANCE, this);
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, POLLING_FREQ, MIN_DISTANCE, this);
            Executors.newScheduledThreadPool(1).schedule(new Runnable() {
                @Override
                public void run() {
                    locationManager.removeUpdates(listener);
                }
            }, MEASURE_TIME, TimeUnit.MILLISECONDS);
        }
    }
}
 
Example 37
Project: InsanityRadio-Android   File: SocializeLocationManager.java   View source code 5 votes vote down vote up
public void requestLocationUpdates(Activity activity, final String provider, final long minTime, final float minDistance, final LocationListener listener) {
	if(lm != null) {
		activity.runOnUiThread(new Runnable() {
			@Override
			public void run() {
				lm.requestLocationUpdates(provider, minTime, minDistance, listener);
			}
		});
	}
}
 
Example 38
Project: smartpublictransport-as   File: LocationFinder.java   View source code 5 votes vote down vote up
public void onLocationChanged(Location location) {
	if (isBetterLocation(location, currentLocation)) {
		currentLocation = location;
		for (LocationListener listener: listeners) {
			listener.onLocationChanged(location);
		}
		if (googleMapListener != null) {
			googleMapListener.onLocationChanged(location);
		}
	}
}
 
Example 39
Project: smartpublictransport-as   File: LocationFinder.java   View source code 5 votes vote down vote up
protected LocationFinder(Activity activity) {
	this.activity = activity;
	this.locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
	this.listeners = new LinkedList<LocationListener>();
	this.googleMapListener = null;
	this.currentLocation = getLastKnownLocation();
	this.locationSaver = activity.getPreferences(Context.MODE_PRIVATE);
	// Define the listener that responds to location updates
	this.internalListenerInstance = new InternalListener();
}
 
Example 40
Project: grocery-reminder   File: GroceryStoreManagerTest.java   View source code 5 votes vote down vote up
@Test
public void whenLocationUpdatesAreRequestedThenLocationListenersAreAddedToTheLocationManager() {
    groceryStoreManager.listenForLocationUpdates(false);

    List<LocationListener> locationListeners = shadowLocationManager.getRequestLocationUpdateListeners();
    assertFalse(locationListeners.isEmpty());
}