Java Code Examples for com.google.android.gms.location.LocationResult#extractResult()
The following examples show how to use
com.google.android.gms.location.LocationResult#extractResult() .
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: LocationUpdateReceiver.java From home-assistant-Android with GNU General Public License v3.0 | 7 votes |
@Override public void onReceive(Context context, Intent intent) { prefs = Utils.getPrefs(context); switch (intent.getAction()) { case Intent.ACTION_BOOT_COMPLETED: case ACTION_START_LOCATION: apiClient = new GoogleApiClient.Builder(context) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); apiClient.connect(); break; case ACTION_LOCATION_UPDATE: if (prefs.getBoolean(Common.PREF_ENABLE_LOCATION_TRACKING, false) && LocationResult.hasResult(intent)) { LocationResult result = LocationResult.extractResult(intent); Location location = result.getLastLocation(); if (location != null) logLocation(location, context); } break; } }
Example 2
Source File: LocationUpdatesBroadcastReceiver.java From background_location_updates with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent != null) { final String action = intent.getAction(); if (ACTION_PROCESS_LOCATION_UPDATE.equals(action)) { LocationResult result = LocationResult.extractResult(intent); if (result != null) { List<Location> locations = result.getLocations(); LocationEntity[] locationEntities = new LocationEntity[locations.size()]; for (int i = 0; i < locations.size(); i++) { locationEntities[i] = LocationEntity.fromAndroidLocation(locations.get(i)); } new TraceInserter(context).execute(locationEntities); } } } }
Example 3
Source File: FusedLocationIntentService.java From android-notification-log with MIT License | 6 votes |
@Override protected void onHandleIntent(@Nullable Intent intent) { if(LocationResult.hasResult(intent)) { LocationResult locationResult = LocationResult.extractResult(intent); Location location = locationResult.getLastLocation(); JSONObject json = new JSONObject(); String str = null; try { long now = System.currentTimeMillis(); json.put("time", now); json.put("offset", TimeZone.getDefault().getOffset(now)); json.put("age", now - location.getTime()); json.put("longitude", location.getLongitude() + ""); json.put("latitude", location.getLatitude() + ""); json.put("accuracy", location.getAccuracy()); str = json.toString(); } catch (JSONException e) { if(Const.DEBUG) e.printStackTrace(); } SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); sp.edit().putString(Const.PREF_LAST_LOCATION, str).apply(); } }
Example 4
Source File: LocationUpdatesBroadcastReceiver.java From background-location-updates-android-o with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent != null) { final String action = intent.getAction(); if (ACTION_PROCESS_UPDATES.equals(action)) { LocationResult result = LocationResult.extractResult(intent); if (result != null) { List<Location> locations = result.getLocations(); LocationResultHelper locationResultHelper = new LocationResultHelper( context, locations); // Save the location data to SharedPreferences. locationResultHelper.saveResults(); // Show notification with the location data. locationResultHelper.showNotification(); Log.i(TAG, LocationResultHelper.getSavedLocationResult(context)); } } } }
Example 5
Source File: LocationUpdatesIntentService.java From background-location-updates-android-o with Apache License 2.0 | 6 votes |
@Override protected void onHandleIntent(Intent intent) { if (intent != null) { final String action = intent.getAction(); if (ACTION_PROCESS_UPDATES.equals(action)) { LocationResult result = LocationResult.extractResult(intent); if (result != null) { List<Location> locations = result.getLocations(); LocationResultHelper locationResultHelper = new LocationResultHelper(this, locations); // Save the location data to SharedPreferences. locationResultHelper.saveResults(); // Show notification with the location data. locationResultHelper.showNotification(); Log.i(TAG, LocationResultHelper.getSavedLocationResult(this)); } } } }
Example 6
Source File: GeofenceReceiver.java From android-sdk with MIT License | 6 votes |
private void handleLocationUpdate(Context context, Intent intent) { LocationResult result = LocationResult.extractResult(intent); LocationAvailability availability = LocationAvailability.extractLocationAvailability(intent); Intent service = SensorbergServiceIntents.getServiceIntentWithMessage( context, SensorbergServiceMessage.MSG_LOCATION_UPDATED); if (result != null) { Location location = result.getLastLocation(); if (location != null) { service.putExtra(SensorbergServiceMessage.EXTRA_LOCATION, location); } } if (availability != null) { service.putExtra(SensorbergServiceMessage.EXTRA_LOCATION_AVAILABILITY, availability.isLocationAvailable()); } if (result != null || availability != null) { context.startService(service); } else { Logger.log.geofenceError("Received invalid location update", null); } }
Example 7
Source File: MyLocationUpdateReceiver.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (LocationResult.hasResult(intent)) { LocationResult locationResult = LocationResult.extractResult(intent); for (Location location : locationResult.getLocations()) { // TODO React to newly received location. } } }
Example 8
Source File: LocationUpdatesBroadcastReceiver.java From openlocate-android with MIT License | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent != null) { final String action = intent.getAction(); if (action.contains(ACTION_PROCESS_UPDATES)) { LocationResult locationResult = LocationResult.extractResult(intent); if (locationResult != null) { new PersistLocationUpdatesTask(goAsync(), context, locationResult).execute(); } } } }
Example 9
Source File: AndroidLocationPlayServiceManager.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
static android.location.Location extractLocationFromIntent(Intent intent) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { LocationResult locationResult = LocationResult.extractResult(intent); if (locationResult == null) { return null; } return locationResult.getLastLocation(); } else { return intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED); } }
Example 10
Source File: LocationUpdatesBroadcastReceiver.java From location-samples with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent != null) { final String action = intent.getAction(); if (ACTION_PROCESS_UPDATES.equals(action)) { LocationResult result = LocationResult.extractResult(intent); if (result != null) { List<Location> locations = result.getLocations(); Utils.setLocationUpdatesResult(context, locations); Utils.sendNotification(context, Utils.getLocationResultTitle(context, locations)); Log.i(TAG, Utils.getLocationUpdatesResult(context)); } } } }
Example 11
Source File: LocationUpdatesIntentService.java From location-samples with Apache License 2.0 | 5 votes |
@Override protected void onHandleIntent(Intent intent) { if (intent != null) { final String action = intent.getAction(); if (ACTION_PROCESS_UPDATES.equals(action)) { LocationResult result = LocationResult.extractResult(intent); if (result != null) { List<Location> locations = result.getLocations(); Utils.setLocationUpdatesResult(this, locations); Utils.sendNotification(this, Utils.getLocationResultTitle(this, locations)); Log.i(TAG, Utils.getLocationUpdatesResult(this)); } } } }
Example 12
Source File: LocationEngineResult.java From mapbox-events-android with MIT License | 4 votes |
private static LocationEngineResult extractGooglePlayResult(Intent intent) { LocationResult result = LocationResult.extractResult(intent); return result != null ? LocationEngineResult.create(result.getLocations()) : null; }
Example 13
Source File: BackgroundLocationBroadcastReceiver.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent != null) { final String action = intent.getAction(); if (ACTION_PROCESS_UPDATES.equals(action)) { LocationResult result = LocationResult.extractResult(intent); Location lastLocation = null; if (result != null) { List<Location> locations = result.getLocations(); for (Location loc : locations){ lastLocation = loc; } } else { return; } if (lastLocation == null) { return; } String dataString = intent.getDataString(); if (dataString == null) { return; } String[] params = dataString.split("[?]"); if (params.length < 2) { return; } Class locationListenerClass; try { locationListenerClass = Class.forName(params[1]); } catch (Throwable t) { return; } boolean shouldStopWhenDone = false; if (!Display.isInitialized()) { shouldStopWhenDone = true; AndroidImplementation.startContext(context); } try { //the 2nd parameter is the class name we need to create LocationListener l = (LocationListener)locationListenerClass.newInstance(); l.locationUpdated(AndroidLocationManager.convert(lastLocation)); } catch (Throwable e) { Log.e("Codename One", "background location error", e); } finally { if (shouldStopWhenDone) { AndroidImplementation.stopContext(context); } } } } }