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


Java GeofencingRequest類代碼示例

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


GeofencingRequest類屬於com.google.android.gms.location包,在下文中一共展示了GeofencingRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addGeofence

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
private void addGeofence() {
    final GeofencingRequest geofencingRequest = createGeofencingRequest();
    if (geofencingRequest == null) return;

    final PendingIntent pendingIntent = createNotificationBroadcastPendingIntent();
    reactiveLocationProvider
            .removeGeofences(pendingIntent)
            .flatMap(new Func1<Status, Observable<Status>>() {
                @Override
                public Observable<Status> call(Status pendingIntentRemoveGeofenceResult) {
                    return reactiveLocationProvider.addGeofences(pendingIntent, geofencingRequest);
                }
            })
            .subscribe(new Action1<Status>() {
                @Override
                public void call(Status addGeofenceResult) {
                    toast("Geofence added, success: " + addGeofenceResult.isSuccess());
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    toast("Error adding geofence.");
                    Log.d(TAG, "Error adding geofence.", throwable);
                }
            });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:GeofenceActivity.java

示例2: createGeofencingRequest

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
private GeofencingRequest createGeofencingRequest() {
    try {
        double longitude = Double.parseDouble(longitudeInput.getText().toString());
        double latitude = Double.parseDouble(latitudeInput.getText().toString());
        float radius = Float.parseFloat(radiusInput.getText().toString());
        Geofence geofence = new Geofence.Builder()
                .setRequestId("GEOFENCE")
                .setCircularRegion(latitude, longitude, radius)
                .setExpirationDuration(Geofence.NEVER_EXPIRE)
                .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT)
                .build();
        return new GeofencingRequest.Builder().addGeofence(geofence).build();
    } catch (NumberFormatException ex) {
        toast("Error parsing input.");
        return null;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:GeofenceActivity.java

示例3: getGeofencingRequest

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
private GeofencingRequest getGeofencingRequest() {
    if (this.place == null || this.place.getLocation() == null) {
        return null;
    }

    // called when the transition associated with the Geofence is triggered)
    List<Geofence> geoFenceList = new ArrayList<Geofence>();
    geoFenceList.add(new Geofence.Builder()
            .setRequestId(GEOFENCE_REQUEST_ID)
            .setCircularRegion(this.place.getLocation().getLatitude(),
                    this.place.getLocation().getLongitude(),
                    GEOFENCE_RADIUS_IN_METERS
            )
            .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_DWELL | Geofence.GEOFENCE_TRANSITION_ENTER)
            .setLoiteringDelay(LOITERING_DELAY_MS)
            .setNotificationResponsiveness(NOTIFICATION_RESPONSIVENESS_MS)
            .setExpirationDuration(Geofence.NEVER_EXPIRE)
            .build());

    GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
    builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER | GeofencingRequest.INITIAL_TRIGGER_DWELL);
    builder.addGeofences(geoFenceList);
    return builder.build();
}
 
開發者ID:hypertrack,項目名稱:hypertrack-live-android,代碼行數:25,代碼來源:ActionManager.java

示例4: startInternal

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
private void startInternal(final Location homeLocation, PendingIntent pendingIntent) {
    GeofencingRequest geofenceRequest = createGeofenceRequest(homeLocation);
    if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        ToastLog.logShort(context, TAG, "Starting Play geofencing...");

        LocationServices.GeofencingApi.addGeofences(
                googleApiClient,
                geofenceRequest,
                pendingIntent
        ).setResultCallback(new ResultCallback<Status>() {
            @Override
            public void onResult(@NonNull Status status) {
                if (status.getStatusMessage() != null) {
                    ToastLog.warnShort(context, TAG, status.getStatusMessage());
                }
            }
        });
    }
}
 
開發者ID:bsautermeister,項目名稱:GeoFencer,代碼行數:20,代碼來源:PlayGeofenceProvider.java

示例5: addGeofence

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
private void addGeofence(PendingIntent pendingIntent, GeofencingRequest geofencingRequest) {
    if (!mGeofencingRequestsMap.containsKey(pendingIntent)) {
        mGeofencingRequestsMap.put(pendingIntent, geofencingRequest);
        if (mGoogleApiClient.isConnected()) {

            if (!isLocationUpdates) {
                // requestLocationUpdates for getting current position
                LocationServices.FusedLocationApi.requestLocationUpdates(
                        mGoogleApiClient, mLocationRequest, this);
                isLocationUpdates = true;
            }

            LocationServices.GeofencingApi.addGeofences(
                    mGoogleApiClient,
                    geofencingRequest,
                    pendingIntent
            ).setResultCallback(this);
        }
    }
}
 
開發者ID:trigor74,項目名稱:travelers-diary,代碼行數:21,代碼來源:GeofenceSetterService.java

示例6: onConnected

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
@Override
public void onConnected(@Nullable Bundle bundle) {
    Log.i(TAG, "Connected to GoogleApiClient");
    try {
        // requestLocationUpdates for getting current position
        LocationServices.FusedLocationApi.requestLocationUpdates(
                mGoogleApiClient, mLocationRequest, this);
        isLocationUpdates = true;

        for (Map.Entry<PendingIntent, GeofencingRequest> entry :
                mGeofencingRequestsMap.entrySet()) {
            addGeofence(entry.getKey(), entry.getValue());
        }
    } catch (SecurityException securityException) {
        // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission.
        showSecurityException(securityException);
    }
}
 
開發者ID:trigor74,項目名稱:travelers-diary,代碼行數:19,代碼來源:GeofenceSetterService.java

示例7: add

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
public void add(GMap.Location location, ResultCallback callback){
    Log.i(TAG, "add " + location.toString());
    String id = location.url.toString()+"\t"+location.name;
    Geofence fence = new Geofence.Builder()
            .setRequestId(id)
            .setCircularRegion( // 500メートル以內
                    location.latitude, location.longitude, 500)
            .setExpirationDuration( // 期限を指定できる
                    Geofence.NEVER_EXPIRE)
            .setTransitionTypes(
                    Geofence.GEOFENCE_TRANSITION_ENTER)
            .build();

    GeofencingRequest request = new GeofencingRequest.Builder()
            .addGeofence(fence) // Geofenceを1つ登録
            .build();

    // IntentServiceで受け取る
    Intent intent = new Intent(context, GeofenceReceiveService.class);

    PendingIntent pIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    LocationServices.GeofencingApi
            .addGeofences(client, request, pIntent)
            .setResultCallback(callback);
}
 
開發者ID:shokai,項目名稱:Android-GMapStars,代碼行數:27,代碼來源:GeofenceManager.java

示例8: registerGeofence

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
@SuppressWarnings("ResourceType")
private void registerGeofence() {
    orchextraLogger.log("Removing " + geofenceUpdates.getDeleteGeofences().size() + " geofences...");
    orchextraLogger.log("Registering " + geofenceUpdates.getNewGeofences().size() + " geofences...");

    List<String> deleteCodeList = androidGeofenceConverter.getCodeList(geofenceUpdates.getDeleteGeofences());

    if (deleteCodeList.size() > 0) {
        LocationServices.GeofencingApi.removeGeofences(googleApiClientConnector.getGoogleApiClient(), deleteCodeList);
    }

    if (geofenceUpdates.getNewGeofences().size() > 0) {
        GeofencingRequest geofencingRequest =
            androidGeofenceConverter.convertGeofencesToGeofencingRequest(geofenceUpdates.getNewGeofences());

        if (googleApiClientConnector.isGoogleApiClientAvailable()) {
            try {
                LocationServices.GeofencingApi.addGeofences(googleApiClientConnector.getGoogleApiClient(), geofencingRequest,
                    geofencePendingIntentCreator.getGeofencingPendingIntent()).setResultCallback(this);
            }catch (Exception e){
                orchextraLogger.log("Exception trying to add geofences: " + e.getMessage(),
                    OrchextraSDKLogLevel.ERROR);
            }
        }
    }
}
 
開發者ID:Orchextra,項目名稱:orchextra-android-sdk,代碼行數:27,代碼來源:GeofenceDeviceRegister.java

示例9: addGeofence

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
private void addGeofence(GeofencingRequest geofencingRequest,
                         PendingIntent geofencePendingIntent) {
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager
            .PERMISSION_GRANTED) {
        return;
    }

    LocationServices.GeofencingApi.addGeofences(
            googleApiClient,
            geofencingRequest,
            geofencePendingIntent
    ).setResultCallback(new ResultCallback<Status>() {
        @Override
        public void onResult(@NonNull Status status) {
            switch (status.getStatusCode()) {
                case CommonStatusCodes.SUCCESS:
                    StatusMessageHandler.showInfoMessage(context, R.string.geofence_enabled, Snackbar.LENGTH_SHORT);
            }

            Log.d(GeofenceApiHandler.class, status.toString());
        }
    });
}
 
開發者ID:Power-Switch,項目名稱:PowerSwitch_Android,代碼行數:24,代碼來源:GeofenceApiHandler.java

示例10: onConnected

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
@Override
public void onConnected(Bundle connectionHint) {
    // We're connected, now we need to create a GeofencingRequest with
    // the geofences we have stored.

    mGeofencingRequest = new GeofencingRequest.Builder().addGeofences(
            mGeofences).build();
    //mGeofencingRequest = new getGeofencingRequest().Builder();
    mPendingIntent = createRequestPendingIntent();

    // This is for debugging only and does not affect
    // geofencing.
    LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);

    // Submitting the request to monitor geofences.
    PendingResult<Status> pendingResult = LocationServices.GeofencingApi
            .addGeofences(mGoogleApiClient, getGeofencingRequest(),
                    mPendingIntent);

    // Set the result callbacks listener to this class.
    pendingResult.setResultCallback(this);
}
 
開發者ID:aarondancer,項目名稱:FenceHouston,代碼行數:24,代碼來源:GeofenceStore.java

示例11: onConnected

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
@Override
public void onConnected(Bundle bundle) {
    // Now we can do the actual logic

    List<Geofence> fences = new ArrayList<Geofence>();
    fences.add(fence.toGeofence(venue));

    geofencingapi = LocationServices.GeofencingApi;

    if(locationClient != null && locationClient.isConnected() && fences.size() > 0){
        GeofencingRequest request = new GeofencingRequest.Builder()
                .addGeofences(fences)
                .build();
        PendingResult<Status> status = geofencingapi.addGeofences(locationClient, request, geofenceUtils.getTransitionPendingIntent(this));
        status.setResultCallback(this, 10, TimeUnit.SECONDS);

        // disconnect will be done in resultlistener
    }else if(locationClient != null && locationClient.isConnected()){
        locationClient.disconnect();
    }
}
 
開發者ID:qbraet,項目名稱:Check-Me-In,代碼行數:22,代碼來源:AddGeofence.java

示例12: location_geofencesCreateTriggerRequest

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
/**
 * Creates a geofencing trigger request. This will make the location service
 * to launch geofencing events (enter/exit events) with the specified
 * geofence list.
 * <br>
 * See Geofences at <a href="http://developer.android.com/intl/es/training/location/geofencing.html">Google developer</a>.
 * <br><br>
 * Note:<br><br>
 * 
 * Requires the permission {@link android.permission.ACCESS_FINE_LOCATION}.
 * 
 * @param geofenceList	The list of Geofences to watch.
 */
public static GeofencingRequest location_geofencesCreateTriggerRequest(List<Geofence> geofenceList) {
	GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
	//The GEOFENCE_TRANSITION_ENTER/GEOFENCE_TRANSITION_EXIT transition 
	//triggers when a device enters/exits a geofence.
	//
	//Specifying INITIAL_TRIGGER_ENTER tells Location services that 
	//GEOFENCE_TRANSITION_ENTER should be triggered if the the device is 
	//already inside the geofence.
	//
	//In many cases, it may be preferable to use instead INITIAL_TRIGGER_DWELL,
	//which triggers events only when the user stops for a defined duration 
	//within a geofence.
    builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
    builder.addGeofences(geofenceList);	    
    return builder.build();
}
 
開發者ID:javocsoft,項目名稱:javocsoft-toolbox,代碼行數:30,代碼來源:ToolBox.java

示例13: settingGeofence

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
public GeofencingRequest settingGeofence(AlarmRealmData data) {
    Geofence geofence = new Geofence.Builder()
            .setRequestId(data.getGeofenceId())
            .setCircularRegion(mTargetLocation.latitude, mTargetLocation.longitude, GEOFENCE_CIRCLE_RADIUS)
            .setExpirationDuration(Geofence.NEVER_EXPIRE)
            .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
            .build();

    GeofencingRequest request = new GeofencingRequest.Builder()
            .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER )
            .addGeofence(geofence)
            .build();
    return request;
}
 
開發者ID:OldBigBuddha,項目名稱:AlarmWithL-T,代碼行數:15,代碼來源:SettingFragment.java

示例14: getGeofenceRequest

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
/***
 *  creates a {@link GeofencingRequest} request object using the mGeofenceList , Arraylist of geofences.
 *  Used by {@link #registerAllGeofences()}
 *
 * @return the GeofencingRequest object.
 */
private GeofencingRequest getGeofenceRequest(){
    GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
    builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
    builder.addGeofences(mGeofenceList);
    return builder.build();
}
 
開發者ID:samagra14,項目名稱:Shush,代碼行數:13,代碼來源:Geofencing.java

示例15: getGeofencingRequest

import com.google.android.gms.location.GeofencingRequest; //導入依賴的package包/類
public static GeofencingRequest getGeofencingRequest(Context context) {
    String geofencingRequestJSON = getSharedPreferences(context).getString(GEOFENCING_REQUEST, null);
    if (geofencingRequestJSON == null) {
        return null;
    }

    Gson gson = new Gson();
    Type type = new TypeToken<GeofencingRequest>() {
    }.getType();

    return gson.fromJson(geofencingRequestJSON, type);
}
 
開發者ID:hypertrack,項目名稱:hypertrack-live-android,代碼行數:13,代碼來源:SharedPreferenceManager.java


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