本文整理汇总了Java中com.google.android.gms.location.GeofencingEvent.getTriggeringGeofences方法的典型用法代码示例。如果您正苦于以下问题:Java GeofencingEvent.getTriggeringGeofences方法的具体用法?Java GeofencingEvent.getTriggeringGeofences怎么用?Java GeofencingEvent.getTriggeringGeofences使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.location.GeofencingEvent
的用法示例。
在下文中一共展示了GeofencingEvent.getTriggeringGeofences方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
protected void onHandleIntent(Intent intent) {
super.onHandleIntent(intent);
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
Timber.e("geofence error code %s", geofencingEvent.getErrorCode());
return;
}
int transitionType = geofencingEvent.getGeofenceTransition();
List<com.google.android.gms.location.Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
Timber.i("Received geofence transition: %s, %s", transitionType, triggeringGeofences);
if (transitionType == com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER) {
for (com.google.android.gms.location.Geofence triggerGeofence : triggeringGeofences) {
triggerNotification(triggerGeofence);
}
} else {
Timber.w("invalid geofence transition type: %s", transitionType);
}
}
示例3: onReceive
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
GeofencingEvent event = GeofencingEvent.fromIntent(intent);
if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER)
Log.d("aken-ajalukku", "Entered geofence!");
else
Log.d("aken-ajalukku", "Exited geofence!");
if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER) {
List<Geofence> geofences = event.getTriggeringGeofences();
ArrayList<PointOfInterest> pois = new ArrayList<>();
for (Geofence gf : geofences) {
pois.add(Data.instance.getPoiById(Integer.parseInt(gf.getRequestId())));
}
createNotification(context, pois);
}
}
示例4: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent != null && !geofencingEvent.hasError()) {
int transition = geofencingEvent.getGeofenceTransition();
// Broadcast an intent containing the geofencing info
Intent geofenceIntent = new Intent(BROADCAST_INTENT_ACTION);
geofenceIntent.putExtra(TRANSITION_EXTRA_ID, transition);
geofenceIntent.putExtra(LOCATION_EXTRA_ID, geofencingEvent.getTriggeringLocation());
ArrayList<String> geofencingIds = new ArrayList<>();
for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
geofencingIds.add(geofence.getRequestId());
}
geofenceIntent.putStringArrayListExtra(GEOFENCES_EXTRA_ID, geofencingIds);
sendBroadcast(geofenceIntent);
}
}
开发者ID:simplesoft-duongdt3,项目名称:Android-App-Template,代码行数:19,代码来源:GeofencingGooglePlayServicesProvider.java
示例5: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Log.d(TAG, "Geofencing event occured");
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
Log.e(TAG, "Location Services error: " + geofencingEvent.getErrorCode());
return;
}
Log.i(TAG, "Location Services geofencingEvent: " + geofencingEvent);
int transitionType = geofencingEvent.getGeofenceTransition();
List<Geofence> triggeredGeofences = geofencingEvent.getTriggeringGeofences();
for (Geofence geofence : triggeredGeofences) {
Log.d(TAG, "onHandle:" + geofence.getRequestId());
processGeofence(geofence, transitionType);
}
}
示例6: geofenceTriggered
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
/**
* 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);
}
示例7: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
String className = intent.getStringExtra("geofenceClass");
String id = intent.getStringExtra("geofenceID");
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
for (com.google.android.gms.location.Geofence gf : geofencingEvent.getTriggeringGeofences()) {
try {
id = gf.getRequestId();
GeofenceListener l = (GeofenceListener) Class.forName(className).newInstance();
if (geofencingEvent.getGeofenceTransition() == com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER) {
l.onEntered(id);
} else if (geofencingEvent.getGeofenceTransition() == com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_EXIT) {
l.onExit(id);
}
} catch (Exception e) {
Log.e("Codename One", "geofence error", e);
}
}
}
示例8: onReceive
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
final ActiveAlarmManager activeAlarmManager = new ActiveAlarmManager(context);
GeofencingEvent event = GeofencingEvent.fromIntent(intent);
if (event.hasError()) {
final String errorMessage = GeofenceStatusCodes.getStatusCodeString(event.getErrorCode());
Log.e(TAG, errorMessage);
return;
}
final int transition = event.getGeofenceTransition();
final List<Geofence> affectedGeofences = event.getTriggeringGeofences();
if (null != affectedGeofences && !affectedGeofences.isEmpty()) {
final Collection<GeoAlarm> affectedAlarms = filter(
Lists.transform(affectedGeofences, getGeoAlarmForGeofenceFn(context)), a -> a != null);
ImmutableSet<UUID> affectedAlarmIds = ImmutableSet.copyOf(transform(affectedAlarms, alarm -> alarm.id));
if (transition == Geofence.GEOFENCE_TRANSITION_ENTER) {
activeAlarmManager.addActiveAlarms(affectedAlarmIds);
} else {
activeAlarmManager.removeActiveAlarms(affectedAlarmIds);
}
}
}
示例9: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
/**
* 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));
}
}
示例10: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
// if the event has an error - log the textual info about it
if (geofencingEvent.hasError()) {
String textualError = LocationUtils.getErrorString(this, geofencingEvent.getErrorCode());
Log.e(TAG, "onHandleIntent: " + textualError);
return;
}
// extract geofence event
int transition = geofencingEvent.getGeofenceTransition();
if (transition == Geofence.GEOFENCE_TRANSITION_ENTER ||
transition == Geofence.GEOFENCE_TRANSITION_EXIT) {
List<Geofence> geoEvents = geofencingEvent.getTriggeringGeofences();
// Get the transition details as a String.
List<String> geofenceDetails = LocationUtils
.getTransitionDetails(this, transition, geoEvents);
if (Utilities.getNotificationsPrefs(getBaseContext())
&& geofenceDetails != null && geofenceDetails.size() > 0) {
sendNotification(geofenceDetails);
}
} else {
Log.e(TAG, getString(R.string.geofence_error_invalid_type, transition));
}
}
示例11: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
/**
* 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();
// Send notification and log the transition details.
// sendNotification(geofenceTransitionDetails);
Intent geofenceIntent = new Intent(GeoFenceUtil.BROADCAST_INTENT_ACTION);
geofenceIntent.putExtra(GeoFenceUtil.TRANSITION_EXTRA_ID, geofenceTransition);
geofenceIntent.putExtra(GeoFenceUtil.LOCATION_EXTRA_ID, geofencingEvent.getTriggeringLocation());
geofenceIntent.putExtra(GeoFenceUtil.GEOFENCES_EXTRA_ID, triggeringGeofences.get(0).getRequestId());
sendBroadcast(geofenceIntent);
} else {
// Log the error.
Log.e(TAG, "Invalid transition type");
}
}
示例12: 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()));
}
示例13: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
/**
* 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()) {
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, "INVALID");
}
}
示例14: getTriggeringGeofenceIds
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
public List<String> getTriggeringGeofenceIds(GeofencingEvent geofencingEvent) {
List<String> triggerGeofenceIds = new ArrayList<>();
if (geofencingEvent == null) {
return Collections.emptyList();
}
List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
if (triggeringGeofences != null) {
for (Geofence triggeringGeofence : triggeringGeofences) {
triggerGeofenceIds.add(triggeringGeofence.getRequestId());
}
}
return triggerGeofenceIds;
}
示例15: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Log.d(TAG, "onHandle");
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage =
GeofenceErrorMessage.getErrorString(this, geofencingEvent.getErrorCode());
Log.e(TAG, errorMessage);
return;
}
mProfileManagerSharedPref = ProfileManagerSharedPref.gcSharedPreferenceInstance(this);
// 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);
Log.i(TAG, geofenceTransitionDetails);
} else {
// Logger the error.
Log.e(TAG, getString(R.string.geofence_transition_invalid_type, geofenceTransition));
}
}