@NonNull @RequiresPermission( anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission" + ".ACCESS_FINE_LOCATION"} ) public Observable<LocationAvailability> requestLocationAvailabilityUpdates(LocationRequest request) { return ObservableTask.create(callback -> { LocationCallback resultCallback = new LocationCallback() { @Override public void onLocationAvailability(LocationAvailability locationAvailability) { super.onLocationAvailability(locationAvailability); callback.onNext(locationAvailability); } }; callback.setDisposeListener(() -> client.removeLocationUpdates(resultCallback)); return client.requestLocationUpdates(request, resultCallback, null); }); }
public void SendLocation(){ try { LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient); if (locationAvailability.isLocationAvailable()) { // Call Location Services LocationRequest locationRequest = new LocationRequest() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setInterval(10000)//10second .setFastestInterval(5000);//5second LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this); Log.v("SendLocation",locationAvailability.toString()); } else { // Do something when Location Provider not available Toast.makeText(getApplicationContext() , "Please Open Location Provider" , Toast.LENGTH_SHORT).show(); } } catch (Exception e){ Log.v("SendLocation exception",e.toString()); } }
@Override protected void onGoogleApiClientReady(GoogleApiClient apiClient, SingleEmitter<Boolean> emitter) { //noinspection MissingPermission LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(apiClient); if (locationAvailability != null) { emitter.onSuccess(locationAvailability.isLocationAvailable()); } else { emitter.onSuccess(false); } }
@NonNull @RequiresPermission( anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission" + ".ACCESS_FINE_LOCATION"} ) public Maybe<LocationAvailability> getLocationAvailability() { return MaybeTask.create(() -> client.getLocationAvailability()); }
@SuppressLint("MissingPermission") @Override protected Task<Void> run(ObservableTaskCallback<LocationAvailability> callback) { ResultCallback resultCallback = new ResultCallback(callback); callback.setDisposeListener(() -> client.removeLocationUpdates(resultCallback)); return client.requestLocationUpdates(this.request, resultCallback, null); }
private boolean checkLocationAvailability() { if (!googleApiClient.isConnected() || !permissionGranted) return false; try { LocationAvailability la = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient); return (la != null && la.isLocationAvailable()); } catch (SecurityException e) { if (!quiet) Log.e(getClass().getSimpleName(), "Error while checking location availability:\n " + e.toString()); if (listener != null) listener.onError(ErrorType.RETRIEVAL, "Could not check location availability:\n" + e.getMessage()); return false; } }
public final void handleMessage(Message paramMessage) { switch (paramMessage.what) { default: return; case 0: this.a.a((LocationResult)paramMessage.obj); return; } this.a.a((LocationAvailability)paramMessage.obj); }
@Override public void onConnected(final Bundle bundle) { if (! mGoogleApiClient.isConnected()) { Log.w("OpenLocationCodes", "GoogleApiClient was disconnected"); return; } if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) { // TODO return; } LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this).setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull final Status status) { if (status.isSuccess()) { Log.d("OpenLocationCodes", "LocationServices: SUCCESS"); final LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(mGoogleApiClient); if (locationAvailability != null && locationAvailability.isLocationAvailable()) { onLocationChanged(LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient)); } } else if (status.isCanceled()) { Log.d("OpenLocationCodes", "LocationServices: CANCELED"); } else if (status.isInterrupted()) { Log.d("OpenLocationCodes", "LocationServices: INTERRUPTED"); } } }); }
public void insertGyroTOserver(final String dt,final String x, final String y, final String z) { if(lat!=0 || lng!=0) { try { LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient); if (locationAvailability.isLocationAvailable()) { // Call Location Services LocationRequest locationRequest = new LocationRequest() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this); } // String queryString = createQueryString(params); final String SITE_URL = "http://168.63.175.28/addGyro.php"; TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); RequestBody formBody = new FormEncodingBuilder() .add("isAdd", "true") .add("imei", telephonyManager.getDeviceId()) .add("time",dt) .add("x", x) .add("y", y) .add("z", z) .add("lat",String.valueOf(lat)) .add("lng",String.valueOf(lng)) .build(); PostForm p= new PostForm(formBody,SITE_URL); final Toast toast = Toast.makeText(getApplicationContext(), "มีการกระแทกเกิดขึ้น", Toast.LENGTH_SHORT); // toast.show(); } catch (Exception ex) { Log.v("ex", ex.toString()); } } }
public void Start(View view){ LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient); if (locationAvailability.isLocationAvailable()) { // Call Location Services LocationRequest locationRequest = new LocationRequest() .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this); } else { // Do something when Location Provider not available } }
public void Stop(View view){ LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient); if (locationAvailability.isLocationAvailable()) { // Call Location Services LocationRequest locationRequest = new LocationRequest() .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this); } else { // Do something when Location Provider not available } }
@Override public void onConnected(Bundle connectionHint) { Log.i("CaptureActivity", "onConnected called"); clientReady = true; //Use a new thread to request location updates for the worker thread. //This new thread waits until the result of the request for updates is complete. Runnable r = new Runnable(){ @Override public void run() { LocationRequest request = new LocationRequest(); request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(5000); LocationCallback locationCallback = new LocationCallback() { @Override public void onLocationAvailability(LocationAvailability availability) { if (!availability.isLocationAvailable()) { locationReady = false; } } public void onLocationResult(LocationResult result) { newestLocation = result.getLastLocation(); } }; PendingResult<Status> requestResult = LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, locationCallback, handler.getLooper()); Status requestStatus = requestResult.await(); locationReady = true; if(requestStatus.isSuccess()) { locationReady = true; Log.i("CaptureActivity", "Location update request result success!"); }else { Log.i("CaptureActivity", "Location update request result: failure!"); } } }; new Thread(r).start(); }
@Override public void onLocationAvailability(LocationAvailability locationAvailability) { Log.i("Debug ", "On Location availability"); }
public ResultCallback(ObservableTaskCallback<LocationAvailability> callback) { this.callback = callback; }
public void onLocationAvailability(LocationAvailability result) { super.onLocationAvailability(result); callback.onNext(result); }
@Override public LocationAvailability getLocationAvailability(GoogleApiClient googleApiClient) { throw new UnsupportedOperationException("Stub!"); }
@Override public void onLocationAvailability(LocationAvailability locationAvailability) { super.onLocationAvailability(locationAvailability); }
public static LocationAvailability a(Parcel paramParcel) { int i = 1; int j = efj.a(paramParcel); int k = 0; int m = 1000; long l = 0L; int n = i; while (paramParcel.dataPosition() < j) { int i1 = paramParcel.readInt(); switch (0xFFFF & i1) { default: efj.b(paramParcel, i1); break; case 1: efj.a(paramParcel, i1, 4); n = paramParcel.readInt(); break; case 1000: efj.a(paramParcel, i1, 4); k = paramParcel.readInt(); break; case 2: efj.a(paramParcel, i1, 4); i = paramParcel.readInt(); break; case 3: efj.a(paramParcel, i1, 8); l = paramParcel.readLong(); break; case 4: efj.a(paramParcel, i1, 4); m = paramParcel.readInt(); } } if (paramParcel.dataPosition() != j) { throw new bm("Overread allowed size end=" + j, paramParcel); } return new LocationAvailability(k, m, n, i, l); }
public final void a(LocationAvailability paramLocationAvailability) { a(1, paramLocationAvailability); }
public final void a(LocationAvailability paramLocationAvailability) { this.a.a(new fvp(this, paramLocationAvailability)); }
@Override public LocationAvailability getLocationAvailabilityWithPackage(String packageName) throws RemoteException { Log.d(TAG, "getLocationAvailabilityWithPackage: " + packageName); return new LocationAvailability(); }
@Override public void onConnected(Bundle bundle) { Log.d(TAG, "onConnected()..." ) ; locationLastKnown = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); if ( locationLastKnown == null ) { LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient) ; if( locationLastKnown == null ){ LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, createLocationRequest(), new LocationListener() { @Override public void onLocationChanged(Location location) { locationLastKnown = location; Log.d(TAG, "LocationServices.FusedLocationApi.requestLocationUpdate)/onLocationChanged()...locationLastKnown=" + locationLastKnown ) ; refreshPositionOnMap(); } }); } boolean locationAvailabilityFlag= false ; if ( locationAvailability != null ) { locationAvailabilityFlag = locationAvailability.isLocationAvailable() ; } Log.d(TAG, "onConnected()...locationAvailability=" + locationAvailability ) ; } Log.d(TAG, "onConnected()...locationLastKnown=" + locationLastKnown ) ; refreshPositionOnMap(); }
public abstract void a(LocationAvailability paramLocationAvailability);
public void a(LocationAvailability paramLocationAvailability) {}
public abstract LocationAvailability c(String paramString);
public fvp(fwh paramfwh, LocationAvailability paramLocationAvailability) {}