本文整理汇总了Java中com.google.android.gms.location.GeofencingEvent.getErrorCode方法的典型用法代码示例。如果您正苦于以下问题:Java GeofencingEvent.getErrorCode方法的具体用法?Java GeofencingEvent.getErrorCode怎么用?Java GeofencingEvent.getErrorCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.location.GeofencingEvent
的用法示例。
在下文中一共展示了GeofencingEvent.getErrorCode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
@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: resolveTransitionFromIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
/**
* Resolves transition information from geofencing intent
*
* @param intent geofencing intent
* @return transition information
* @throws RuntimeException if information cannot be resolved
*/
static GeoTransition resolveTransitionFromIntent(Intent intent) throws RuntimeException {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent == null) {
throw new RuntimeException("Geofencing event is null, cannot process");
}
if (geofencingEvent.hasError()) {
if (geofencingEvent.getErrorCode() == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) {
throw new GeofenceNotAvailableException();
}
throw new RuntimeException("ERROR: " + GeofenceStatusCodes.getStatusCodeString(geofencingEvent.getErrorCode()));
}
GeoEventType event = supportedTransitionEvents.get(geofencingEvent.getGeofenceTransition());
if (event == null) {
throw new RuntimeException("Transition is not supported: " + geofencingEvent.getGeofenceTransition());
}
Set<String> triggeringRequestIds = new ArraySet<>();
for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
triggeringRequestIds.add(geofence.getRequestId());
}
Location location = geofencingEvent.getTriggeringLocation();
return new GeoTransition(event, triggeringRequestIds, new GeoLatLng(location.getLatitude(), location.getLongitude()));
}
示例3: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
protected void onHandleIntent(Intent intent) {
Log.d(MainActivity.TAG, "onHandleIntent(" + intent + ")");
Lesson nearestLesson = getNearestLesson(true);
if (intent.hasExtra(EXTRA_TRANSITION) && intent.hasExtra(EXTRA_GEOFENCE_LIST) && intent.hasExtra(EXTRA_TRIGGERING_LOCATION)) {
GeofencingEvent geoFenceEvent = GeofencingEvent.fromIntent(intent);
if (geoFenceEvent.hasError()) {
int errorCode = geoFenceEvent.getErrorCode();
Log.e(MainActivity.TAG, "Location Services error: " + errorCode);
cancelSelf();
setSilent(false);
} else {
int transitionType = geoFenceEvent.getGeofenceTransition();
if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER) {
setSilent(true);
sendNotificationIfNeeded(nearestLesson);
} else if (transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) {
cancelSelf();
setSilent(false);
}
}
} else if (intent.hasExtra(EXTRA_TRIGGERED_SELF) && intent.getBooleanExtra(EXTRA_TRIGGERED_SELF, false)) {
sendNotificationIfNeeded(nearestLesson);
} else {
cancelSelf();
setSilent(false);
}
}
示例4: getGeofenceTransition
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
public GeoPointEventType getGeofenceTransition(GeofencingEvent geofencingEvent) {
if (!geofencingEvent.hasError()) {
int transition = geofencingEvent.getGeofenceTransition();
switch (transition) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
return GeoPointEventType.ENTER;
case Geofence.GEOFENCE_TRANSITION_DWELL:
return GeoPointEventType.STAY;
case Geofence.GEOFENCE_TRANSITION_EXIT:
return GeoPointEventType.EXIT;
}
}
throw new GeofenceEventException("Geofence Event Error was produced, code is: " + geofencingEvent.getErrorCode());
}
示例5: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
String notificationText = "Not a geo event";
GeofencingEvent geoEvent = GeofencingEvent.fromIntent(intent);
if (geoEvent != null) {
if (geoEvent.hasError()) {
notificationText = "Error : " + geoEvent.getErrorCode();
} else {
int transition = geoEvent.getGeofenceTransition();
String transitionStr;
switch (transition) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
transitionStr = "Enter-";
break;
case Geofence.GEOFENCE_TRANSITION_EXIT:
transitionStr = "Exit-";
break;
case Geofence.GEOFENCE_TRANSITION_DWELL:
transitionStr = "Dwell-";
break;
default:
transitionStr = "Unknown-";
}
List<Geofence> triggeringGeo = geoEvent.getTriggeringGeofences();
StringBuilder strBuilder = new StringBuilder();
strBuilder.append(transitionStr);
for (int i = 0; i < triggeringGeo.size(); i++) {
Geofence geo = triggeringGeo.get(i);
strBuilder.append(geo.getRequestId());
strBuilder.append("-");
}
notificationText = strBuilder.toString();
}
}
sendNotification(notificationText);
}
示例6: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = "" + 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) {
List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {
// Get the geofences that were triggered. A single event can trigger
// multiple geofences.
EventBus.getDefault().post(new EnterFence(triggeringGeofences));
// Get the transition details as a String.
Log.d(TAG, "" + geofenceTransition);
// String geofenceTransitionDetails = getGeofenceTransitionDetails(
// this,
// geofenceTransition,
// triggeringGeofences
// );
// Send notification and log the transition details.
// sendNotification(geofenceTransitionDetails);
Log.i(TAG, "" + geofenceTransition);
} else if(geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
EventBus.getDefault().post(new ExitFence(triggeringGeofences));
} else {
// Log the error.
Log.e(TAG, "geofence error");
}
}
示例7: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
String notificationText = "Not a geo event";
GeofencingEvent geoEvent = GeofencingEvent.fromIntent(intent);
if (geoEvent != null) {
if (geoEvent.hasError()) {
notificationText = "Error : " + geoEvent.getErrorCode();
} else {
int transition = geoEvent.getGeofenceTransition();
String transitionStr;
switch (transition) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
transitionStr = "Enter-";
break;
case Geofence.GEOFENCE_TRANSITION_EXIT:
transitionStr = "Exit-";
break;
case Geofence.GEOFENCE_TRANSITION_DWELL:
transitionStr = "Dwell-";
break;
default:
transitionStr = "Unknown-";
}
StorableGeofenceManager manager = new StorableGeofenceManager(this);
List<Geofence> triggeringGeo = geoEvent.getTriggeringGeofences();
StringBuilder strBuilder = new StringBuilder();
strBuilder.append(transitionStr);
for (int i = 0; i < triggeringGeo.size(); i++) {
Geofence geo = triggeringGeo.get(i);
StorableGeofence storableGeofence = manager.getGeofence(geo.getRequestId());
strBuilder.append(geo.getRequestId());
if (storableGeofence != null && storableGeofence.getAdditionalData() != null) {
HashMap<String, Object> additionalData = storableGeofence.getAdditionalData();
strBuilder.append("(").append(additionalData.get(MainActivity.ADDITIONAL_DATA_TIME)).append(" - ").append(additionalData.get(MainActivity.ADDITIONAL_DATA_PACKAGE)).append(")");
}
strBuilder.append("-");
}
notificationText = strBuilder.toString();
}
}
sendNotification(notificationText);
}