Проблема Android Vitals только с одной точкой доступа в геозону - PullRequest
0 голосов
/ 23 ноября 2018

В нашем приложении несколько дней назад мы столкнулись с множеством проблем с жизненно важными устройствами для Android, поэтому мы отключили все наши горячие точки геозоны и жизненно важные органы, но теперь мы включили только 1 горячую точку с радиусом 15 км и включили обратный вызов для ENTER, EXIT& DWELL, но мы снова сталкиваемся с насущной проблемой только с 1 точкой доступа .. не знаю, что здесь происходит, если у кого-то есть идеи, пожалуйста, помогите .. ниже код -

public class GeoFenceManager implements OnCompleteListener<Void> {

/**
 * Provides access to the Geofencing API.
 */
private GeofencingClient mGeofencingClient;

/**
 * The list of geofences used in this sample.
 */
private ArrayList<Geofence> mGeofenceList;

/**
 * Used when requesting to add or remove geofences.
 */
private PendingIntent mGeofencePendingIntent;

private WeakReference<Context> context;

private static GeoFenceManager geoFenceManager;

public static synchronized GeoFenceManager getInstance(Context context) {
    if (geoFenceManager == null) {
        geoFenceManager = new GeoFenceManager();
    }
    GeoFenceManager.geoFenceManager.context = new WeakReference<>(context);
    return geoFenceManager;
}

private GeoFenceManager() {

}

public void init(Context context) {
    mGeofencePendingIntent = null;
    // Empty list for storing geofences.
    if (mGeofenceList == null) {
        mGeofenceList = new ArrayList<>();
    } else {
        mGeofenceList.clear();
    }
    mGeofencingClient = LocationServices.getGeofencingClient(context);
    populateGeofenceList();
    addGeofences();
}

@Override
public void onComplete(@NonNull Task<Void> task) {
    if (task.isSuccessful()) {
        Logger.DEBUG("Geofence added");
    } else {
        // Get the status code for the error and log it using a user-friendly message.
        String errorMessage = GeofenceErrorMessages.getErrorString(context.get(), task.getException());
        Logger.DEBUG(errorMessage);
    }
}

/**
 * Adds geofences. This method should be called after the user has granted the location
 * permission.
 */
@SuppressWarnings("MissingPermission")
private void addGeofences() {
    if (!checkPermissions()) {
        return;
    }
    if (mGeofencingClient != null) {
        mGeofencingClient.removeGeofences(getGeofencePendingIntent()).addOnCompleteListener(this);
        if (mGeofenceList != null && mGeofenceList.size() > 0) {
            mGeofencingClient.addGeofences(getGeofencingRequest(), getGeofencePendingIntent())
                    .addOnCompleteListener(this);
        }
    }
}

/**
 * Builds and returns a GeofencingRequest. Specifies the list of geofences to be monitored.
 * Also specifies how the geofence notifications are initially triggered.
 */
private GeofencingRequest getGeofencingRequest() {
    GeofencingRequest.Builder builder = new GeofencingRequest.Builder();

    // The INITIAL_TRIGGER_ENTER flag indicates that geofencing service should trigger a
    // GEOFENCE_TRANSITION_ENTER notification when the geofence is added and if the device
    // is already inside that geofence.
    builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER | GeofencingRequest.INITIAL_TRIGGER_DWELL);

    // Add the geofences to be monitored by geofencing service.
    builder.addGeofences(mGeofenceList);

    // Return a GeofencingRequest.
    return builder.build();
}

/**
 * Removes geofences. This method should be called after the user has granted the location
 * permission.
 */
@SuppressWarnings("MissingPermission")
public void removeGeofences() {
    if (!checkPermissions()) {
        return;
    }
    if (mGeofenceList != null) {
        mGeofenceList.clear();
    }
    if (mGeofencingClient != null) {
        mGeofencingClient.removeGeofences(getGeofencePendingIntent()).addOnCompleteListener(this);
    }
}

/**
 * Return the current state of the permissions needed.
 */
private boolean checkPermissions() {
    int permissionState = ActivityCompat.checkSelfPermission(context.get(),
            Manifest.permission.ACCESS_FINE_LOCATION);
    return permissionState == PackageManager.PERMISSION_GRANTED;
}

/**
 * Gets a PendingIntent to send with the request to add or remove Geofences. Location Services
 * issues the Intent inside this PendingIntent whenever a geofence transition occurs for the
 * current list of geofences.
 *
 * @return A PendingIntent for the IntentService that handles geofence transitions.
 */
private PendingIntent getGeofencePendingIntent() {
    // Reuse the PendingIntent if we already have it.
    if (mGeofencePendingIntent != null) {
        return mGeofencePendingIntent;
    }
    Intent intent = new Intent(context.get(), GeofenceTransitionsIntentService.class);
    // We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when calling
    // addGeofences() and removeGeofences().
    return PendingIntent.getService(context.get(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

/*
 * This sample hard codes geofence data. A real app might dynamically create geofences based on
 * the user's location.
 */
private void populateGeofenceList() {
    mGeofenceList.clear();
    HotSpotResponse hotSpotResponse = PreferenceKeeper.getHotspotData(context.get());
    if (hotSpotResponse != null && hotSpotResponse.hotspots != null && hotSpotResponse.hotspots.size() > 0) {
        for (HotSpots hotSpot : hotSpotResponse.hotspots) {
            if (hotSpot.radius > 0) {
                mGeofenceList.add(new Geofence.Builder()
                        // Set the request ID of the geofence. This is a string to identify this
                        // geofence.
                        .setNotificationResponsiveness(hotSpot.notificationResponsiveTime != null ? hotSpot.notificationResponsiveTime : 420000)
                        .setRequestId(hotSpot.isOuter ? AppConstant.MY_GEOFENCE_ID : hotSpot.id + "")

                        // Set the circular region of this geofence.
                        .setCircularRegion(
                                hotSpot.center.lat,
                                hotSpot.center.lng,
                                hotSpot.radius
                        )

                        // Set the expiration duration of the geofence. This geofence gets automatically
                        // removed after this period of time.
                        .setExpirationDuration(Geofence.NEVER_EXPIRE)

                        .setLoiteringDelay((int) hotSpot.dwellTime) //hard coded the dwell time as 10 minutes for now for each hotspot

                        // Set the transition types of interest. Alerts are only generated for these
                        // transition. We track entry and exit transitions in this sample.
                        .setTransitionTypes(hotSpot.transitionType != 0 ? hotSpot.transitionType : 7)
                        // Create the geofence.
                        .build());
            }
        }
    }
}

}

...