當前位置: 首頁>>代碼示例>>Java>>正文


Java Geofence.GEOFENCE_TRANSITION_ENTER屬性代碼示例

本文整理匯總了Java中com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER屬性的典型用法代碼示例。如果您正苦於以下問題:Java Geofence.GEOFENCE_TRANSITION_ENTER屬性的具體用法?Java Geofence.GEOFENCE_TRANSITION_ENTER怎麽用?Java Geofence.GEOFENCE_TRANSITION_ENTER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在com.google.android.gms.location.Geofence的用法示例。


在下文中一共展示了Geofence.GEOFENCE_TRANSITION_ENTER屬性的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);
  }
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:23,代碼來源:ReceiveTransitionsIntentService.java

示例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! ");
    }
 
開發者ID:abicelis,項目名稱:Remindy,代碼行數:16,代碼來源:GeofenceNotificationIntentService.java

示例3: onReceive

@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);
    }
}
 
開發者ID:rasmussaks,項目名稱:aken-ajalukku,代碼行數:16,代碼來源:GeofenceTransitionsReceiver.java

示例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);
}
 
開發者ID:googlesamples,項目名稱:io2015-codelabs,代碼行數:25,代碼來源:UtilityService.java

示例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);
    }
}
 
開發者ID:arshiyakhanum,項目名稱:ProfileManager,代碼行數:24,代碼來源:GeofenceTransitionIntentService.java

示例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();
}
 
開發者ID:Preston-Landers,項目名稱:QuietPlaces,代碼行數:23,代碼來源:QuietPlaceMapMarker.java

示例7: onHandleIntent

@Override
protected void onHandleIntent( Intent intent ) {
	NotificationCompat.Builder builder = new NotificationCompat.Builder( this );
	builder.setSmallIcon( R.drawable.ic_launcher );
	builder.setDefaults( Notification.DEFAULT_ALL );
	builder.setOngoing( true );

	int transitionType = LocationClient.getGeofenceTransition( intent );
	if( transitionType == Geofence.GEOFENCE_TRANSITION_ENTER ) {
		builder.setContentTitle( "Geofence Transition" );
		builder.setContentText( "Entering Geofence" );
		mNotificationManager.notify( 1, builder.build() );
	}
	else if( transitionType == Geofence.GEOFENCE_TRANSITION_EXIT ) {
		builder.setContentTitle( "Geofence Transition" );
		builder.setContentText( "Exiting Geofence" );
		mNotificationManager.notify( 1, builder.build() );
	}
}
 
開發者ID:Lakkichand,項目名稱:AndroidDemoProjects,代碼行數:19,代碼來源:GeofencingService.java

示例8: onReceive

@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);
		}
	}
}
 
開發者ID:maurizi,項目名稱:Geoclock,代碼行數:25,代碼來源:GeofenceReceiver.java

示例9: 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());
}
 
開發者ID:mauimauer,項目名稱:AndroidWearable-Samples,代碼行數:29,代碼來源:MainActivity.java

示例10: 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";
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:GeofenceBroadcastReceiver.java

示例11: 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);
}
 
開發者ID:samagra14,項目名稱:Shush,代碼行數:34,代碼來源:GeofenceBroadcastReceiver.java

示例12: 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);
    }
}
 
開發者ID:hypertrack,項目名稱:hypertrack-live-android,代碼行數:18,代碼來源:GeofenceTransitionsIntentService.java

示例13: 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";
}
 
開發者ID:bsautermeister,項目名稱:GeoFencer,代碼行數:11,代碼來源:GeofenceUtils.java

示例14: getStatusForTransitionType

private int getStatusForTransitionType(int transitionType) {
  if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER ||
      transitionType == Geofence.GEOFENCE_TRANSITION_DWELL) {
    return GeofenceStatus.INSIDE;
  } else {
    return GeofenceStatus.OUTSIDE;
  }
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:8,代碼來源:LocationManagerImplementation.java

示例15: 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 "";
    }


}
 
開發者ID:abicelis,項目名稱:Remindy,代碼行數:29,代碼來源:GeofenceNotificationIntentService.java


注:本文中的com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。