本文整理汇总了Java中com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_EXIT属性的典型用法代码示例。如果您正苦于以下问题:Java Geofence.GEOFENCE_TRANSITION_EXIT属性的具体用法?Java Geofence.GEOFENCE_TRANSITION_EXIT怎么用?Java Geofence.GEOFENCE_TRANSITION_EXIT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.android.gms.location.Geofence
的用法示例。
在下文中一共展示了Geofence.GEOFENCE_TRANSITION_EXIT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onHandleIntent
@Override
protected void onHandleIntent(Intent intent) {
try {
GeofencingEvent event = GeofencingEvent.fromIntent(intent);
if (event.hasError()) {
int errorCode = event.getErrorCode();
Log.d("Location Client Error with code: " + errorCode);
} else {
int transitionType = event.getGeofenceTransition();
List<Geofence> triggeredGeofences = event.getTriggeringGeofences();
if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER ||
transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) {
LocationManagerImplementation locationManager = (LocationManagerImplementation)
ActionManager.getLocationManager();
if (locationManager != null) {
locationManager.updateStatusForGeofences(triggeredGeofences, transitionType);
}
}
}
} catch (Throwable t) {
Util.handleException(t);
}
}
示例2: handleLogTransition
private void handleLogTransition(int geofenceTransition) {
String transitionStr = "";
switch (geofenceTransition) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
transitionStr = "GEOFENCE_TRANSITION_ENTER";
break;
case Geofence.GEOFENCE_TRANSITION_EXIT:
transitionStr = "GEOFENCE_TRANSITION_EXIT";
break;
case Geofence.GEOFENCE_TRANSITION_DWELL:
transitionStr = "GEOFENCE_TRANSITION_DWELL";
break;
}
Log.d(TAG, transitionStr + " detected! ");
}
示例3: onHandleIntent
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent event = GeofencingEvent.fromIntent(intent);
if (event != null && !event.hasError()) {
int transition = event.getGeofenceTransition();
Geofence fence = event.getTriggeringGeofences().get(0);
Bundle extras = intent.getExtras();
String id = fence.getRequestId();
Matcher m = Pattern.compile("^([^\\t]+)\\t([^\\t]+)$").matcher(id);
if(m.find()){
Uri uri = Uri.parse(m.group(1));
String name = m.group(2);
switch (transition) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
Log.i("TAG", uri.toString()+" "+name);
sendNotification(uri, name);
break;
case Geofence.GEOFENCE_TRANSITION_EXIT:
break;
}
}
}
}
示例4: geofenceTriggered
/**
* Called when a geofence is triggered
*/
private void geofenceTriggered(Intent intent) {
Log.v(TAG, ACTION_GEOFENCE_TRIGGERED);
// Check if geofences are enabled
boolean geofenceEnabled = Utils.getGeofenceEnabled(this);
// Extract the geofences from the intent
GeofencingEvent event = GeofencingEvent.fromIntent(intent);
List<Geofence> geofences = event.getTriggeringGeofences();
if (geofenceEnabled && geofences != null && geofences.size() > 0) {
if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER) {
// Trigger the notification based on the first geofence
showNotification(geofences.get(0).getRequestId(), Constants.USE_MICRO_APP);
} else if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_EXIT) {
// Clear notifications
clearNotificationInternal();
clearRemoteNotifications();
}
}
UtilityReceiver.completeWakefulIntent(intent);
}
示例5: getTransitionString
/**
0* Maps geofence transition types to their human-readable equivalents.
*
* @param transitionType A transition type constant defined in Geofence
* @return A String indicating the type of transition
*/
private String getTransitionString(int transitionType) {
switch (transitionType) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
Log.d(TAG, "entered");
return getString(R.string.geofence_transition_entered);
case Geofence.GEOFENCE_TRANSITION_EXIT:
Log.d(TAG, "exited");
return getString(R.string.geofence_transition_exited);
case Geofence.GEOFENCE_TRANSITION_DWELL:
Log.d(TAG, "dwelling");
return ("In the area");
default:
Log.e(TAG, "unknown transition");
return getString(R.string.unknown_geofence_transition);
}
}
示例6: buildGeofence
/**
* Returns a Geofence object corresponding to the current settings of this quiet place.
*
* @return constructed Geofence object
*/
private Geofence buildGeofence() {
QuietPlace quietPlace = getQuietPlace();
if (quietPlace == null) {
Log.e(TAG, "can't buildGeofence: getQuietPlace() is null");
return null;
}
int transitionType = Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT;
float radius = (float) getRadius();
return new Geofence.Builder()
.setRequestId(getGeofenceId())
.setTransitionTypes(transitionType)
.setCircularRegion(
quietPlace.getLatitude(),
quietPlace.getLongitude(),
radius)
.setExpirationDuration(Config.GEOFENCE_MAX_LIFETIME_MS)
.build();
}
示例7: createGeofences
/**
* In this sample, the geofences are predetermined and are hard-coded here. A real app might
* dynamically create geofences based on the user's location.
*/
public void createGeofences() {
// Create internal "flattened" objects containing the geofence data.
mAndroidBuildingGeofence = new SimpleGeofence(
ANDROID_BUILDING_ID, // geofenceId.
ANDROID_BUILDING_LATITUDE,
ANDROID_BUILDING_LONGITUDE,
ANDROID_BUILDING_RADIUS_METERS,
GEOFENCE_EXPIRATION_TIME,
Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT
);
mYerbaBuenaGeofence = new SimpleGeofence(
YERBA_BUENA_ID, // geofenceId.
YERBA_BUENA_LATITUDE,
YERBA_BUENA_LONGITUDE,
YERBA_BUENA_RADIUS_METERS,
GEOFENCE_EXPIRATION_TIME,
Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT
);
// Store these flat versions in SharedPreferences and add them to the geofence list.
mGeofenceStorage.setGeofence(ANDROID_BUILDING_ID, mAndroidBuildingGeofence);
mGeofenceStorage.setGeofence(YERBA_BUENA_ID, mYerbaBuenaGeofence);
mGeofenceList.add(mAndroidBuildingGeofence.toGeofence());
mGeofenceList.add(mYerbaBuenaGeofence.toGeofence());
}
示例8: mapTransition
private String mapTransition(int event) {
switch (event) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
return "ENTER";
case Geofence.GEOFENCE_TRANSITION_EXIT:
return "EXIT";
default:
return "UNKNOWN";
}
}
示例9: onReceive
/***
* Handles the Broadcast message sent when the Geofence Transition is triggered
* Careful here though, this is running on the main thread so make sure you start an AsyncTask for
* anything that takes longer than say 10 second to run
*
* @param context
* @param intent
*/
@Override
public void onReceive(Context context, Intent intent) {
//get the geofencing event sent from the intent
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
Log.e(LOG_TAG, String.format("Error Code : %s", geofencingEvent.getErrorCode()));
return;
}
//get the transition type
int geoFenceTransition = geofencingEvent.getGeofenceTransition();
//Check which transition type has triggered the event
if (geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {
RingerUtils.setRingerMode(context, AudioManager.RINGER_MODE_SILENT);
} else if (geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
RingerUtils.setRingerMode(context, AudioManager.RINGER_MODE_NORMAL);
} else {
Log.e(LOG_TAG, String.format("Unknown Transition , %d", geoFenceTransition));
return;
}
//Send the notification
sendNotification(context, geoFenceTransition);
}
示例10: getTransitionString
/**
* Maps geofence transition types to their human-readable equivalents.
*
* @param transitionType A transition type constant defined in Geofence
* @return A String indicating the type of transition
*/
private String getTransitionString(int transitionType) {
switch (transitionType) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
return getString(R.string.geofence_transition_entered);
case Geofence.GEOFENCE_TRANSITION_EXIT:
return getString(R.string.geofence_transition_exited);
case Geofence.GEOFENCE_TRANSITION_DWELL:
return getString(R.string.geofence_transition_dwelled);
default:
return getString(R.string.unknown_geofence_transition);
}
}
示例11: transitionString
public static String transitionString(@NonNull final GeofencingEvent geofencingEvent) {
int transitionCode = geofencingEvent.getGeofenceTransition();
if (transitionCode == Geofence.GEOFENCE_TRANSITION_EXIT)
return "EXIT";
else if (transitionCode == Geofence.GEOFENCE_TRANSITION_ENTER)
return "ENTER";
else if (transitionCode == Geofence.GEOFENCE_TRANSITION_DWELL)
return "DWELL";
else
return "UNKNOWN";
}
示例12: getGeofenceNotificationTitle
private String getGeofenceNotificationTitle(int geofenceTransition, Geofence triggeringGeofence) {
String transition = "";
switch (geofenceTransition) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
transition = getResources().getString(R.string.notification_service_geofence_enter);
break;
case Geofence.GEOFENCE_TRANSITION_EXIT:
transition = getResources().getString(R.string.notification_service_geofence_exit);
break;
case Geofence.GEOFENCE_TRANSITION_DWELL:
//transition = getResources().getString(R.string.notification_service_geofence_dwell);
transition = getResources().getString(R.string.notification_service_geofence_enter);
break;
}
int placeId = Integer.valueOf(triggeringGeofence.getRequestId());
try {
Place place = new RemindyDAO(this).getPlace(placeId);
return String.format(Locale.getDefault(),
getResources().getString(R.string.notification_service_geofence_title),
transition,
place.getAlias());
} catch (PlaceNotFoundException e) {
return "";
}
}
示例13: onHandleIntent
/**
* Handles incoming intents.
* @param intent sent by Location Services. This Intent is provided to Location
* Services (inside a PendingIntent) when addGeofences() is called.
*/
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = GeofenceErrorMessages.getErrorString(this,
geofencingEvent.getErrorCode());
Log.e(TAG, errorMessage);
return;
}
// Get the transition type.
int geofenceTransition = geofencingEvent.getGeofenceTransition();
// Test that the reported transition was of interest.
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
// Get the geofences that were triggered. A single event can trigger multiple geofences.
List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
// Get the transition details as a String.
String geofenceTransitionDetails = getGeofenceTransitionDetails(
this,
geofenceTransition,
triggeringGeofences
);
// Send notification and log the transition details.
sendNotification(geofenceTransitionDetails);
Log.i(TAG, geofenceTransitionDetails);
} else {
// Log the error.
Log.e(TAG, getString(R.string.geofence_transition_invalid_type, geofenceTransition));
}
}
示例14: getTransitionString
/**
* Maps geofence transition types to their human-readable equivalents.
*
* @param transitionType A transition type constant defined in Geofence
* @return A String indicating the type of transition
*/
private String getTransitionString(int transitionType) {
switch (transitionType) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
return getString(R.string.geofence_transition_entered);
case Geofence.GEOFENCE_TRANSITION_EXIT:
return getString(R.string.geofence_transition_exited);
default:
return getString(R.string.unknown_geofence_transition);
}
}
示例15: getTransitionString
/**
* Maps geofence transition types to their human-readable equivalents.
*
* @param transitionType A transition type constant defined in Geofence
* @return A String indicating the type of transition
*/
private String getTransitionString(int transitionType) {
switch (transitionType) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
return "Entered";
case Geofence.GEOFENCE_TRANSITION_EXIT:
return "Exited";
default:
return "Unknown Transition";
}
}