Example usage for android.location LocationManager KEY_PROXIMITY_ENTERING

List of usage examples for android.location LocationManager KEY_PROXIMITY_ENTERING

Introduction

In this page you can find the example usage for android.location LocationManager KEY_PROXIMITY_ENTERING.

Prototype

String KEY_PROXIMITY_ENTERING

To view the source code for android.location LocationManager KEY_PROXIMITY_ENTERING.

Click Source Link

Document

Key used for the Bundle extra holding a boolean indicating whether a proximity alert is entering (true) or exiting (false)..

Usage

From source file:org.jboss.aerogear.cordova.geo.ProximityReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String id = intent.getData().getLastPathSegment();
    String status = intent.getBooleanExtra(LocationManager.KEY_PROXIMITY_ENTERING, false) ? "entered" : "left";

    Log.d(TAG, "received proximity alert for region " + id + " with status " + status);

    GeofencingPlugin.sendNotification(id, status);
    if (!GeofencingPlugin.isInForeground()) {
        createNotification(context, id, status);
    }/*from w w  w. ja v a2s  .c om*/
}

From source file:com.example.programming.proximityalerts.ProximityAlertService.java

@Override
    public void onLocationChanged(Location location) {
        float distance = getDistance(location);

        if (distance <= radius && !inProximity) {
            inProximity = true;/* w  ww.  j av a2s  . c  o m*/
            Log.i(TAG, "Entering Proximity");

            Intent intent = new Intent(ProximityPendingIntentFactory.PROXIMITY_ACTION);
            intent.putExtra(LocationManager.KEY_PROXIMITY_ENTERING, true);
            sendBroadcast(intent);
        } else if (distance > radius && inProximity) {
            inProximity = false;
            Log.i(TAG, "Exiting Proximity");

            Intent intent = new Intent(ProximityPendingIntentFactory.PROXIMITY_ACTION);
            intent.putExtra(LocationManager.KEY_PROXIMITY_ENTERING, true);
            sendBroadcast(intent);
        } else {
            float distanceFromRadius = Math.abs(distance - radius);

            // Calculate the distance to the edge of the user-defined radius
            // around the target location
            float locationEvaluationDistance = (distanceFromRadius - location.getAccuracy()) / 2;

            if (ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(this,
                            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            locationManager.removeUpdates(this);
            float updateDistance = Math.max(1, locationEvaluationDistance);

            String provider;
            if (distanceFromRadius <= location.getAccuracy()
                    || LocationManager.GPS_PROVIDER.equals(location.getProvider())) {
                provider = LocationManager.GPS_PROVIDER;
            } else {
                provider = LocationManager.NETWORK_PROVIDER;
            }

            locationManager.requestLocationUpdates(provider, 0, updateDistance, this);
        }
    }

From source file:it.polimi.proximityapi.TechnologyManager.java

/**
 * Implementation of BroadcastReceiver methods
 *///from  w ww .j  ava2s  .com

@Override
public void onReceive(Context context, Intent intent) {

    //Retrieve POI data from intent
    String proxDataName = intent.getStringExtra(JsonStrings.NAME);
    boolean enterEvent = intent.getBooleanExtra(LocationManager.KEY_PROXIMITY_ENTERING, false);
    String log = (enterEvent ? "Entry in " : "Exit from ") + " geofence " + proxDataName;
    Log.i(TAG, log);

    for (ProximityData p : proximityData)
        if (p.getID().equals(proxDataName)) {

            if (p.isNeed_geofence()) {
                //callback for geofence events
                if (enterEvent) {
                    p.setWithin_geofence(true);
                    p.getProxListener().onEnterGeofenceArea(null);
                    bleProvider.onNewProximityRequest(p);
                } else {
                    p.setWithin_geofence(false);
                    p.getProxListener().onExitGeofenceArea(null);
                    bleProvider.onRemoveProximityRequest(p);
                }
            }
        }
}