本文整理汇总了Java中com.google.android.gms.location.GeofencingEvent类的典型用法代码示例。如果您正苦于以下问题:Java GeofencingEvent类的具体用法?Java GeofencingEvent怎么用?Java GeofencingEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeofencingEvent类属于com.google.android.gms.location包,在下文中一共展示了GeofencingEvent类的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包/类
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent fenceEvent = GeofencingEvent.fromIntent(intent);
if (fenceEvent.hasError()) {
String errorMessage = GeofenceStatusCodes.getStatusCodeString(fenceEvent.getErrorCode());
Timber.i(errorMessage);
return;
}
Timber.i("We got a geofence intent");
if (fenceEvent.getGeofenceTransition() != Geofence.GEOFENCE_TRANSITION_DWELL
|| fenceEvent.getTriggeringGeofences().isEmpty()) {
return;
}
String placeId = fenceEvent.getTriggeringGeofences().get(0).getRequestId();
Realm realm = Realm.getDefaultInstance();
Place place = Place.findFirst(realm, placeId);
String title = place != null ?
getString(R.string.geofence_notification_place_title, place.getName()) :
getString(R.string.geofence_notification_title);
String content = getString(R.string.geofence_notification_content);
String imageUrl = place != null ? place.getFirstImage(GEOFENCE_LARGE_ICON_SIZE) : null;
realm.close();
sendNotification(title, content, placeId, imageUrl);
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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
示例6: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入依赖的package包/类
@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;
}
}
}
}
示例7: processGeofenceIntentPending
import com.google.android.gms.location.GeofencingEvent; //导入依赖的package包/类
public void processGeofenceIntentPending(Intent intent) {
if (geofenceHandler != null &&
controller != null &&
orchextraLogger != null) {
try {
GeofencingEvent geofencingEvent = geofenceHandler.getGeofencingEvent(intent);
List<String> geofenceIds = geofenceHandler.getTriggeringGeofenceIds(geofencingEvent);
GeoPointEventType transition = geofenceHandler.getGeofenceTransition(geofencingEvent);
orchextraLogger.log("Localizado: " + transition.getStringValue());
if (geofenceIds != null && !geofenceIds.isEmpty()) {
controller.processTriggers(geofenceIds, transition);
}
} catch (GeofenceEventException geofenceEventException) {
orchextraLogger.log(geofenceEventException.getMessage(), OrchextraSDKLogLevel.ERROR);
}
}
}
示例8: 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);
}
}
示例9: 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);
}
示例10: 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);
}
}
}
示例11: 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);
}
}
}
示例12: onReceive
import com.google.android.gms.location.GeofencingEvent; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
GeofencingEvent event = GeofencingEvent.fromIntent(intent);
String transition = mapTransition(event.getGeofenceTransition());
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Geofence action")
.setContentText(transition)
.setTicker("Geofence action")
.build();
nm.notify(0, notification);
}
示例13: onReceive
import com.google.android.gms.location.GeofencingEvent; //导入依赖的package包/类
/***
* 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);
}
示例14: onHandleIntent
import com.google.android.gms.location.GeofencingEvent; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = ErrorMessages.getGeofenceErrorString(this,
geofencingEvent.getErrorCode());
HyperLog.e(TAG, errorMessage);
return;
}
// Get the transition type.
int geofenceTransition = geofencingEvent.getGeofenceTransition();
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) {
HyperLog.i(TAG, "User is dwelling in geo fence.");
ActionManager.getSharedManager(getApplicationContext()).OnGeoFenceSuccess();
} else {
// Log the error.
HyperLog.e(TAG, getString(R.string.geofence_transition_invalid_type,
geofenceTransition));
}
// Get the geofences that were triggered. A single event can trigger
// multiple geofences.
String geofenceTransitionDetails = getGeofenceTransitionDetails(geofenceTransition,
geofencingEvent.getTriggeringGeofences());
HyperLog.i(TAG, "GeoFenceTransition Details: " + geofenceTransitionDetails);
}
}
示例15: onReceive
import com.google.android.gms.location.GeofencingEvent; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
notification = new SimpleNotification(context);
if (geofencingEvent != null && !geofencingEvent.hasError()) {
handleReceivedEventOnBackgroundThread(geofencingEvent);
} else {
// we end up here e.g. when the user deactivates GPS on the device
ToastLog.warnLong(context, TAG, "Error: " + geofencingEvent.getErrorCode());
}
}