当前位置: 首页>>代码示例>>Java>>正文


Java LocationClient.getGeofenceTransition方法代码示例

本文整理汇总了Java中com.google.android.gms.location.LocationClient.getGeofenceTransition方法的典型用法代码示例。如果您正苦于以下问题:Java LocationClient.getGeofenceTransition方法的具体用法?Java LocationClient.getGeofenceTransition怎么用?Java LocationClient.getGeofenceTransition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.gms.location.LocationClient的用法示例。


在下文中一共展示了LocationClient.getGeofenceTransition方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onHandleIntent

import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@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,代码行数:20,代码来源:GeofencingService.java

示例2: onHandleIntent

import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
    Log.v(TAG, "onHandleIntent");
    if (LocationClient.hasError(intent)) {
        int errorCode = LocationClient.getErrorCode(intent);
        Log.e(TAG, "Location Services error: " + Integer.toString(errorCode));
    } else {
        int transitionType = LocationClient.getGeofenceTransition(intent);
        if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER) {
            final long stationId = Long.parseLong(LocationClient.getTriggeringGeofences(intent).get(0).getRequestId());
            Log.d(TAG, "Entered in:" + LocationClient.getTriggeringGeofences(intent));
            MorphoClientFactory morphoClientFactory = new MorphoClientFactory(getApplicationContext());
            Schedules schedules = morphoClientFactory.get(Schedules.class);
            schedules.fetch()
                .comingSchedules(stationId)
                .only("CIRCUITO") // TODO: retrieve bus route from preferences
                .limitTo(3)
                .loadSchedules(new AsyncTaskAdapter<List<Schedule>>() {

                    @Override
                    public void onPostExecute(List<Schedule> result) {
                        Log.d(TAG, "Result: " + result);
                        if (!result.isEmpty()) notificationManager.notify(++notificationId, buildNotification(stationId, result));
                    }
                });
        } else Log.e(TAG, "Geofence transition error: " + Integer.toString(transitionType));
    }
}
 
开发者ID:dan-zx,项目名称:morpho,代码行数:29,代码来源:ReceiveTransitionsIntentService.java

示例3: onHandleIntent

import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
	Log.d(GeoAlarmUtils.APPTAG,
			"ReceiveTransitionsItentService HandleIntent");

	// First check for errors
	if (LocationClient.hasError(intent)) {
		int errorCode = LocationClient.getErrorCode(intent);
		// Log the error
		Log.e(GeoAlarmUtils.APPTAG,
				getString(R.string.geofence_transition_error_detail,
						errorCode));
	} else {
		int transition = LocationClient.getGeofenceTransition(intent);
		// Test that a valid transition was reported
		if (transition == Geofence.GEOFENCE_TRANSITION_ENTER) {
			Log.d(GeoAlarmUtils.APPTAG, "GeoAlarm triggered");
			long alarmSetTime = intent.getExtras().getLong(
					GeoAlarmUtils.EXTRA_ALARM_SET_TIME);
			long currentTime = SystemClock.elapsedRealtime();
			if (currentTime - alarmSetTime > GeoAlarmUtils.MIN_DTIME) {
				boolean isUseVbirate = intent.getExtras().getBoolean(
						GeoAlarmUtils.EXTRA_USE_VIBRATE);
				String ringtoneUri = intent.getExtras().getString(
						GeoAlarmUtils.EXTRA_RINGTONE_URI);
				sendNotification(ringtoneUri, isUseVbirate);
			}
		}
	}

	ReceiveTransitionsBroadcastReceiver.completeWakefulIntent(intent);
}
 
开发者ID:gvellut,项目名称:MapAlarmist,代码行数:33,代码来源:ReceiveTransitionsIntentService.java

示例4: onReceive

import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    if (!intent.getAction().equals(LocationActivity.ACTION_GEOFENCE)) {
        return;
    }
    boolean hasError = LocationClient.hasError(intent);
    if (hasError) {
        // This is an intent that indicates error.
        Log.v(LocationActivity.TAG, "hasError == true");
        return;
    }
    int transition = LocationClient.getGeofenceTransition(intent);
    List<Geofence> list = LocationClient.getTriggeringGeofences(intent);
    if (transition == -1 || list == null) {
        Log.v(LocationActivity.TAG, "list == null OR " + transition);
        return;
    }
    Log.v(LocationActivity.TAG, "geo_fence transition == " + transition);
    ArrayList<String> requestIds = new ArrayList<String>();
    for (Geofence geoFence : list) {
        requestIds.add(geoFence.getRequestId());
    }
    Bundle bundle = new Bundle();
    bundle.putStringArrayList("request_ids", requestIds);

    // Create a new intent and set extra arguments which contain the
    // request_ids of geofences triggered and corresponding transition.
    Intent myIntent = new Intent(context, LocationActivity.class);
    myIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
            | Intent.FLAG_ACTIVITY_NEW_TASK);
    myIntent.putExtra("RECEIVER_STARTED", true);
    myIntent.putExtra("geo_fences", bundle);
    myIntent.putExtra("transition", transition);

    if (LocationActivity.isAppForeground) {
        context.startActivity(myIntent);
    } else {
        // Send a notification when the app is in the background
    }
}
 
开发者ID:saxman,项目名称:maps-android-codelabs,代码行数:41,代码来源:GeoFenceIntentReceiver.java

示例5: onHandleIntent

import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
/**
 * Handles incoming intents
 * @param intent The Intent sent by Location Services. This Intent is provided
 * to Location Services (inside a PendingIntent) when you call addGeofences()
 */
@Override
protected void onHandleIntent(Intent intent) {

    // Create a local broadcast Intent
    Intent broadcastIntent = new Intent();

    // Give it the category for all intents sent by the Intent Service
    broadcastIntent.addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES);

    // First check for errors
    if (LocationClient.hasError(intent)) {

        // Get the error code
        int errorCode = LocationClient.getErrorCode(intent);

        // Get the error message
        String errorMessage = LocationServiceErrorMessages.getErrorString(this, errorCode);

        // Log the error
        Log.e(GeofenceUtils.APPTAG,
                getString(R.string.geofence_transition_error_detail, errorMessage)
        );

        // Set the action and error message for the broadcast intent
        broadcastIntent.setAction(GeofenceUtils.ACTION_GEOFENCE_ERROR)
                       .putExtra(GeofenceUtils.EXTRA_GEOFENCE_STATUS, errorMessage);

        // Broadcast the error *locally* to other components in this app
        LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);

    // If there's no error, get the transition type and create a notification
    } else {

        // Get the type of transition (entry or exit)
        int transition = LocationClient.getGeofenceTransition(intent);

        // Test that a valid transition was reported
        if (
                (transition == Geofence.GEOFENCE_TRANSITION_ENTER)
                ||
                (transition == Geofence.GEOFENCE_TRANSITION_EXIT)
           ) {

            // Post a notification
            List<Geofence> geofences = LocationClient.getTriggeringGeofences(intent);
            String[] geofenceIds = new String[geofences.size()];
            for (int index = 0; index < geofences.size() ; index++) {
                geofenceIds[index] = geofences.get(index).getRequestId();
            }
            String ids = TextUtils.join(GeofenceUtils.GEOFENCE_ID_DELIMITER,geofenceIds);
            String transitionType = getTransitionString(transition);

            sendNotification(transitionType, ids);

            // Log the transition type and a message
            Log.d(GeofenceUtils.APPTAG,
                    getString(
                            R.string.geofence_transition_notification_title,
                            transitionType,
                            ids));
            Log.d(GeofenceUtils.APPTAG,
                    getString(R.string.geofence_transition_notification_text));

        // An invalid transition was reported
        } else {
            // Always log as an error
            Log.e(GeofenceUtils.APPTAG,
                    getString(R.string.geofence_transition_invalid_type, transition));
        }
    }
}
 
开发者ID:knr1,项目名称:ch.bfh.mobicomp,代码行数:77,代码来源:ReceiveTransitionsIntentService.java

示例6: onHandleIntent

import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
/**
 * Handles incoming intents.
 * @param intent The 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) {
    // First check for errors.
    if (LocationClient.hasError(intent)) {
        int errorCode = LocationClient.getErrorCode(intent);
        Log.e(TAG, "Location Services error: " + errorCode);
    } else {
        // Get the type of geofence transition (i.e. enter or exit in this sample).
        int transitionType = LocationClient.getGeofenceTransition(intent);
        // Create a DataItem when a user enters one of the geofences. The wearable app will
        // receive this and create a notification to prompt him/her to check in.
        if (Geofence.GEOFENCE_TRANSITION_ENTER == transitionType) {
            // Connect to the Google Api service in preparation for sending a DataItem.
            mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
            // Get the geofence id triggered. Note that only one geofence can be triggered at a
            // time in this example, but in some cases you might want to consider the full list
            // of geofences triggered.
            String triggeredGeofenceId = LocationClient.getTriggeringGeofences(intent).get(0)
                    .getRequestId();
            // Create a DataItem with this geofence's id. The wearable can use this to create
            // a notification.
            final PutDataMapRequest putDataMapRequest =
                    PutDataMapRequest.create(GEOFENCE_DATA_ITEM_PATH);
            putDataMapRequest.getDataMap().putString(KEY_GEOFENCE_ID, triggeredGeofenceId);
            if (mGoogleApiClient.isConnected()) {
                Wearable.DataApi.putDataItem(
                    mGoogleApiClient, putDataMapRequest.asPutDataRequest()).await();
            } else {
                Log.e(TAG, "Failed to send data item: " + putDataMapRequest
                         + " - Client disconnected from Google Play Services");
            }
            mGoogleApiClient.disconnect();
        } else if (Geofence.GEOFENCE_TRANSITION_EXIT == transitionType) {
            // Delete the data item when leaving a geofence region.
            mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
            Wearable.DataApi.deleteDataItems(mGoogleApiClient, GEOFENCE_DATA_ITEM_URI).await();
            mGoogleApiClient.disconnect();
        }
    }
}
 
开发者ID:mauimauer,项目名称:AndroidWearable-Samples,代码行数:46,代码来源:GeofenceTransitionsIntentService.java

示例7: onHandleIntent

import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
/**
     * Handle the intent received by the service.
     * @param intent This will be a geofence transition intent.
     */
    protected void onHandleIntent(Intent intent) {
//        Log.d(LOG_TAG, "onHandleIntentCalled.");
        // First check for errors
        if (LocationClient.hasError(intent)) {
            // Get the error code with a static method
            int errorCode = LocationClient.getErrorCode(intent);
            // Log the error
            Log.e("ReceiveTransitionsIntentService", "Location Services error: " +
                            Integer.toString(errorCode));

        /*
         * If there's no error, get the transition type and the IDs
         * of the geofence or geofences that triggered the transition
         */
        } else {
            manageCurrentGeofencesCriticalSection.acquireUninterruptibly();
            // Get the type of transition (entry or exit)
            int transitionType = LocationClient.getGeofenceTransition(intent);
            // Test that a valid transition was reported
            if ((transitionType == Geofence.GEOFENCE_TRANSITION_ENTER)
                            || (transitionType == Geofence.GEOFENCE_TRANSITION_EXIT)) {
                List <Geofence> triggerList = LocationClient.getTriggeringGeofences(intent);
                Location triggerLocation = LocationClient.getTriggeringLocation(intent);

                if(transitionType == Geofence.GEOFENCE_TRANSITION_ENTER){
                    addToCurrentGeofences(triggerList);
                } else {
                    removeFromCurrentGeofences(triggerList);
                }
                String currentGeofenceNames = "Current Geofences:";
                for(LocationEnvironmentVariable v: currentGeofences)
                    currentGeofenceNames += v.getLocationName() + "; ";
                manageCurrentGeofencesCriticalSection.release();
                startService(BaseService.getServiceIntent(this, null,
                        BaseService.ACTION_DETECT_ENVIRONMENT));
            } else {
                // An invalid transition was reported
                Log.e("ReceiveTransitionsIntentService", "Geofence transition error: " +
                                Integer.toString(transitionType));
            }
        }
    }
 
开发者ID:aravindsagar,项目名称:SmartLockScreen,代码行数:47,代码来源:GeoFenceIntentService.java

示例8: onHandleIntent

import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
/**
 * Handles incoming intents
 *
 * @param intent The Intent sent by Location Services. This Intent is provided
 *               to Location Services (inside a PendingIntent) when you call addGeofences()
 */
@Override
protected void onHandleIntent(Intent intent) {

    // Create a local broadcast Intent
    Intent broadcastIntent = new Intent();
    // Give it the category for all intents sent by the Intent Service
    broadcastIntent.addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES);

    Log.d(TAG, "### ------------------------------------------------------- ###");
    Log.d(TAG, "### Geofence onHandleIntent : " + intent);
    printExtras(intent.getExtras());
    Log.d(TAG, "### ------------------------------------------------------- ###");

    // First check for errors
    if (LocationClient.hasError(intent)) {
        int errorCode = LocationClient.getErrorCode(intent);
        String errorMessage = LocationServiceErrorMessages.getErrorString(this, errorCode);
        // Log the error
        Log.e(TAG, getString(R.string.geofence_transition_error_detail, errorMessage));
        // Set the action and error message for the broadcast intent
        broadcastIntent.setAction(GeofenceUtils.ACTION_GEOFENCE_ERROR)
                .putExtra(GeofenceUtils.EXTRA_GEOFENCE_STATUS, errorMessage);

        // Broadcast the error *locally* to other components in this app
        LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);
    } else {
        //Future<Location> location = LastLocationFinder.getLastBestLocation(this, );
        // If there's no error, get the transition type and create a notification
        // Get the type of transition (entry or exit)
        int transition = LocationClient.getGeofenceTransition(intent);

        // Test that a valid transition was reported
        if ((transition == Geofence.GEOFENCE_TRANSITION_ENTER) || (transition == Geofence.GEOFENCE_TRANSITION_EXIT)) {
            // Post a notification
            List<Geofence> geofences = LocationClient.getTriggeringGeofences(intent);
            MessageActionEnum transitionType = getTransitionString(transition);
            // Send Notification
            String[] geofenceIds = extractGeofenceRequestsId(geofences);
            sendNotification(transitionType, geofenceIds);
            // Log the transition type and a message
            Log.d(TAG, "### GeoFence Violation : " + transitionType + " for " + geofences.size() + " geofences (like" + geofences.get(0));
        } else {
            // An invalid transition was reported
            // Always log as an error
            Log.e(TAG, "### Geofence transition error. Invalid type " + transition +
                    " in geofences %2$s");
        }
    }
}
 
开发者ID:gabuzomeu,项目名称:geoPingProject,代码行数:56,代码来源:ReceiveTransitionsIntentService.java

示例9: onHandleIntent

import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
/**
 * Handles incoming intents
 * 
 * @param intent
 *            The Intent sent by Location Services. This Intent is provided
 *            to Location Services (inside a PendingIntent) when you call
 *            addGeofences()
 */
@Override
protected void onHandleIntent(final Intent intent) {

    if (isCorrectIntent(intent)) {

        if (LocationClient.hasError(intent)) {

            int errorCode = LocationClient.getErrorCode(intent);

            // Get the error message
            String errorMessage = LocationServiceErrorMessages.getErrorString(this, errorCode);
            Log.d(LOG_TAG, "Error: " + errorMessage);

            CommonUtils.showShortToast(this, errorMessage);
        } else {
            // Get the type of transition (entry or exit)
            int transition = LocationClient.getGeofenceTransition(intent);

            // Test that a valid transition was reported (just an enter
            // transition, uncomment the commented
            // code to allow too transition exit
            if ((transition == Geofence.GEOFENCE_TRANSITION_ENTER)
            /* || (transition == Geofence.GEOFENCE_TRANSITION_EXIT) */) {

                List<Geofence> geofenceList = LocationClient.getTriggeringGeofences(intent);
                String[] geofenceIds = new String[geofenceList.size()];

                // We can remove this loop since we are using just one id
                // (with more this is necessary)
                for (int i = 0; i < geofenceIds.length; i++) {
                    String placeId = geofenceList.get(i).getRequestId();
                    if (placeId.equals(mPlaceId)) {
                        geofenceIds[i] = placeId;
                        Log.d(LOG_TAG, "geofence ID received: " + placeId);
                        SimpleGeofence geofence = new SimpleGeofenceStore(this).getGeofence(geofenceIds[i]);
                        if (geofence != null) {
                            NotificationsManager.getInstance(this).showLocationReminderNotification(geofence);
                        }
                    }
                }
            }
            // An invalid transition was reported
            else {
                Log.e(LOG_TAG, "Geofence transition error: " + Integer.toString(transition));
            }
        }
    }
}
 
开发者ID:CesarValiente,项目名称:GeofencesDemo,代码行数:57,代码来源:ReceiveTransitionsIntentService.java

示例10: onReceive

import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    if (!intent.getAction().equals(LocationActivity.ACTION_GEOFENCE)) {
        return;
    }
    boolean hasError = LocationClient.hasError(intent);
    if (hasError) {
        // This is an intent that indicates error.
        Log.v(LocationActivity.TAG, "hasError == true");
        return;
    }
    int transition = LocationClient.getGeofenceTransition(intent);
    List<Geofence> list = LocationClient.getTriggeringGeofences(intent);
    if (transition == -1 || list == null) {
        Log.v(LocationActivity.TAG, "list == null OR " + transition);
        return;
    }
    Log.v(LocationActivity.TAG, "geo_fence transition == " + transition);
    ArrayList<String> requestIds = new ArrayList<String>();
    for (Geofence geoFence : list) {
        requestIds.add(geoFence.getRequestId());
    }
    Bundle bundle = new Bundle();
    bundle.putStringArrayList("request_ids", requestIds);

    // Create a new intent and set extra arguments which contain the
    // request_ids of geofences triggered and corresponding transition.
    Intent myIntent = new Intent(context, LocationActivity.class);
    myIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
            | Intent.FLAG_ACTIVITY_NEW_TASK);
    myIntent.putExtra("RECEIVER_STARTED", true);
    myIntent.putExtra("geo_fences", bundle);
    myIntent.putExtra("transition", transition);

    if (LocationActivity.isAppForeground) {
        context.startActivity(myIntent);
    } else {
        // Send a notification when the app is in the background
        String transitionText = transition == Geofence.GEOFENCE_TRANSITION_ENTER ?
                context.getResources().getString(R.string.enter) :
                context.getResources().getString(R.string.leave);

        Bitmap genFenceBitmap = BitmapFactory.decodeResource(context.getResources(),
                R.drawable.geofence);

        Notification n = new NotificationCompat.Builder(context)
                .setContentTitle(context.getResources().getString(R.string.app_name))
                .setSmallIcon(R.drawable.ic_notify)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(genFenceBitmap)
                        .setSummaryText(transitionText))
                .setContentText(transitionText)
                .setContentIntent(PendingIntent.getActivity(context, 0, myIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT))
                .setAutoCancel(true).build();

        NotificationManager nm = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        nm.notify(1, n);
    }
}
 
开发者ID:saxman,项目名称:maps-android-codelabs,代码行数:62,代码来源:GeoFenceIntentReceiver.java


注:本文中的com.google.android.gms.location.LocationClient.getGeofenceTransition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。