Java 类com.google.android.gms.location.ActivityRecognitionResult 实例源码

项目:cordova-plugin-quintech-background-geolocation    文件:ActivityRecognitionLocationProvider.java   
@Override
public void onReceive(Context context, Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    //Find the activity with the highest percentage
    lastActivity = getProbableActivity(detectedActivities);

    Log.d(TAG, "MOST LIKELY ACTIVITY: " + getActivityString(lastActivity.getType()) + " " + lastActivity.getConfidence());

    if (lastActivity.getType() == DetectedActivity.STILL) {
        if (config.isDebugging()) {
            Toast.makeText(context, "Detected STILL Activity", Toast.LENGTH_SHORT).show();
        }
        // stopTracking();
        // we will delay stop tracking after position is found
    } else {
        if (config.isDebugging()) {
            Toast.makeText(context, "Detected ACTIVE Activity", Toast.LENGTH_SHORT).show();
        }
        startTracking();
    }
    //else do nothing
}
项目:googleplayAPI    文件:DetectedActivitiesIntentService.java   
/**
 * Handles incoming intents.
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@SuppressWarnings("unchecked")
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    PreferenceManager.getDefaultSharedPreferences(this)
        .edit()
        .putString(Constants.KEY_DETECTED_ACTIVITIES,
            Utils.detectedActivitiesToJson(detectedActivities))
        .apply();

    // Log each activity.
    Log.i(TAG, "activities detected");
    for (DetectedActivity da: detectedActivities) {
        Log.i(TAG, Utils.getActivityString(
            getApplicationContext(),
            da.getType()) + " " + da.getConfidence() + "%"
        );
    }
}
项目:googleplayAPI    文件:MainActivity.java   
@Override
protected void onNewIntent(Intent intent) {
    Log.v(TAG, "onNewIntent");

    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    //get most probable activity
    DetectedActivity probably = result.getMostProbableActivity();
    if (probably.getConfidence() >= 50) {  //doc's say over 50% is likely, under is not sure at all.
        speech(getActivityString(probably.getType()));
    }
    logger.append("Most Probable: " +getActivityString(probably.getType()) + " "+ probably.getConfidence()+"%\n" );
    //or we could go through the list, which is sorted by most likely to least likely.
    List<DetectedActivity> fulllist = result.getProbableActivities();
    for (DetectedActivity da: fulllist) {
        if (da.getConfidence() >=50) {
            logger.append("-->" + getActivityString(da.getType()) + " " + da.getConfidence() + "%\n");
            speech(getActivityString(da.getType()));

        }
    }
}
项目:cordova-background-geolocation-services    文件:BackgroundLocationUpdateService.java   
@Override
public void onReceive(Context context, Intent intent) {
  ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
  ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

  //Find the activity with the highest percentage
  lastActivity = Constants.getProbableActivity(detectedActivities);

  Log.w(TAG, "MOST LIKELY ACTIVITY: " + Constants.getActivityString(lastActivity.getType()) + " " + lastActivity.getConfidence());

  Intent mIntent = new Intent(Constants.CALLBACK_ACTIVITY_UPDATE);
  mIntent.putExtra(Constants.ACTIVITY_EXTRA, detectedActivities);
  getApplicationContext().sendBroadcast(mIntent);
  Log.w(TAG, "Activity is recording" + isRecording);

  if(lastActivity.getType() == DetectedActivity.STILL && isRecording) {
      showDebugToast(context, "Detected Activity was STILL, Stop recording");
      stopRecording();
  } else if(lastActivity.getType() != DetectedActivity.STILL && !isRecording) {
      showDebugToast(context, "Detected Activity was ACTIVE, Start Recording");
      startRecording();
  }
  //else do nothing
}
项目:footstep    文件:DetectedActivitiesIntentService.java   
/**
 * Handles incoming intents.
 *
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    Intent localIntent = new Intent(Constants.BROADCAST_ACTION);

    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    // Log each activity.
    Log.i(TAG, "activities detected");
    for (DetectedActivity da : detectedActivities) {
        Log.i(TAG, Constants.getActivityString(
                        getApplicationContext(),
                        da.getType()) + " " + da.getConfidence() + "%"
        );
    }

    // Broadcast the list of detected activities.
    localIntent.putExtra(Constants.ACTIVITY_EXTRA, detectedActivities);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}
项目:androidApp    文件:DetectedActivitiesIntentService.java   
/**
 * Handles incoming intents.
 *
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    Intent localIntent = new Intent(Constants.ACTIVITY_BROADCAST_ACTION);

    if (result == null) {
        return;
    }

    ArrayList<DetectedActivity> res = new ArrayList<>();
    for (DetectedActivity d : result.getProbableActivities()) {
        if (d.getConfidence() > Constants.MIN_ACTIVITY_CONFIDENCE) {
            res.add(d);
        }
    }

    // Broadcast the list of detected activities.
    localIntent.putExtra(Constants.ACTIVITY_EXTRA, res);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}
项目:cordova-plugin-mauron85-background-geolocation-phonegapbuild    文件:FusedLocationService.java   
@Override
public void onReceive(Context context, Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    //Find the activity with the highest percentage
    lastActivity = getProbableActivity(detectedActivities);

    Log.d(TAG, "MOST LIKELY ACTIVITY: " + getActivityString(lastActivity.getType()) + " " + lastActivity.getConfidence());

    if (lastActivity.getType() == DetectedActivity.STILL) {
        if (config.isDebugging()) {
            Toast.makeText(context, "Detected STILL Activity", Toast.LENGTH_SHORT).show();
        }
        // stopTracking();
        // we will delay stop tracking after position is found
    } else {
        if (config.isDebugging()) {
            Toast.makeText(context, "Detected ACTIVE Activity", Toast.LENGTH_SHORT).show();
        }
        startTracking();
    }
    //else do nothing
}
项目:Pandora-sdk-android    文件:PandoraSDK.java   
@Subscribe 
public void messageAvailable(AndroidEventMessage m) {

     if(m.getId().equals(Configuration.NO_CONNECTION)){
         //detener geo e ibacon services
         Log.i("pandora","stoping services because NO CONNECTION");
         stopServices(contexto);
     }else if(m.getId().equals(Configuration.CONNECTION)){
        //activar geo e ibacon services
         Log.i("pandora","restarting services because CONNECTION");
         startServices(contexto, this.iBeacon, true);
     }else if(m.getId().equals(Configuration.NEW_ACTIVITY) && GeoService.receivedFix>2){ 

         ActivityRecognitionResult result = (ActivityRecognitionResult) m.getContent(); 
         String activity = parseActivity(result.getMostProbableActivity());
         Log.i("pandora","new activity: "+activity);  
         if(result.getMostProbableActivity().getType()==DetectedActivity.STILL && result.getMostProbableActivity().getConfidence()>80){
             Log.i("pandora","stoping services because STILL");
             stopServices(contexto);
         }else {
             Log.i("pandora","restarting services because NOT STILL");  
             startServices(contexto, this.iBeacon, true);
         }
     } 
}
项目:android-play-location    文件:DetectedActivitiesIntentService.java   
/**
 * Handles incoming intents.
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@SuppressWarnings("unchecked")
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    PreferenceManager.getDefaultSharedPreferences(this)
            .edit()
            .putString(Constants.KEY_DETECTED_ACTIVITIES,
                    Utils.detectedActivitiesToJson(detectedActivities))
            .apply();

    // Log each activity.
    Log.i(TAG, "activities detected");
    for (DetectedActivity da: detectedActivities) {
        Log.i(TAG, Utils.getActivityString(
                        getApplicationContext(),
                        da.getType()) + " " + da.getConfidence() + "%"
        );
    }
}
项目:ShutUpAndDrive    文件:DetectedActivityIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result =
                ActivityRecognitionResult.extractResult(intent);
        DetectedActivity mostProbableActivity = result.getMostProbableActivity();
        int confidence = mostProbableActivity.getConfidence();
        int activityType = mostProbableActivity.getType();
        long waitTime = UserSettings.getNotDrivingTime(this);
        boolean diffTimeOK = (new Date().getTime() - waitTime) >= Utils.minutesToMillis(10);
        if (confidence >= Utils.DETECTION_THRESHOLD && activityType == DetectedActivity.IN_VEHICLE && diffTimeOK) {
            if (!CarMode.running) {
                if (UserSettings.getGPS(this) && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
                    startService(new Intent(this, SpeedService.class));
                else
                    startService(new Intent(this, CarMode.class));
            }
        } else if (confidence >= Utils.DETECTION_THRESHOLD) {
            stopService(new Intent(this, CarMode.class));
            UserSettings.setGPSDrive(this, false);
        }

    }
}
项目:MoST    文件:GoogleActivityRecognitionInput.java   
@Override
public void onReceive(Context context, Intent intent) {

    if (ActivityRecognitionResult.hasResult(intent)) {
        // Get the update
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        // Get the most probable activity
        DetectedActivity mostProbableActivity = result.getMostProbableActivity();
        int confidence = mostProbableActivity.getConfidence();
        int activityType = mostProbableActivity.getType();
        String activityName = getNameFromType(activityType);

        DataBundle b = _bundlePool.borrowBundle();
        b.putInt(KEY_CONFIDENCE, confidence);
        b.putString(KEY_RECOGNIZED_ACTIVITY, activityName);
        b.putLong(Input.KEY_TIMESTAMP, System.currentTimeMillis());
        b.putInt(Input.KEY_TYPE, getType().toInt());
        post(b);

    }

}
项目:autotracks-android    文件:ActivityRecognitionService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (mPreferenceUtils.isActivityUpdatesStarted()) {
        if (ActivityRecognitionResult.hasResult(intent)) {
            mPreferenceUtils.setLastActivityTime(System.currentTimeMillis());
            ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
            boolean moving = isMoving(result);
            mPreferenceUtils.setMoving(moving);
            if (moving) {
                if (!mPreferenceUtils.isLocationUpdatesStarted()) {
                    mLocationUpdatesController.startLocationUpdates();
                }
            } else {
                if (mPreferenceUtils.isLocationUpdatesStarted()) {
                    mLocationUpdatesController.stopLocationUpdates();
                }
            }
        }
    }
}
项目:autotracks-android    文件:ActivityRecognitionService.java   
/**
 * Detecta si el dispositivo se encuentra en un vehículo en movimiento o no
 *
 * @param result resultado de la detección de actividad
 * @return <code>true</code> si se encuentra en un vehículo.
 */
private boolean isMoving(ActivityRecognitionResult result) {
    long currentTime = System.currentTimeMillis();

    DetectedActivity mostProbableActivity = result.getMostProbableActivity();
    int confidence = mostProbableActivity.getConfidence();
    int type = mostProbableActivity.getType();

    if ((type == ON_FOOT || type == RUNNING || type == WALKING) && confidence > 75) {
        return false;
    }

    if (type == IN_VEHICLE && confidence > 75) {
        mPreferenceUtils.setDetectionTimeMillis(currentTime);
        return true;
    }

    if (mPreferenceUtils.wasMoving()) {
        long tolerance = mPreferenceUtils.getActivityRecognitionToleranceMillis();
        long lastDetectionTime = mPreferenceUtils.getDetectionTimeMillis();
        long elapsedTime = currentTime - lastDetectionTime;
        return elapsedTime <= tolerance;
    }

    return false;
}
项目:SensingKit-Android    文件:SKActivityRecognitionIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {

    // If the intent contains an update
    if (ActivityRecognitionResult.hasResult(intent)) {

        // Get the update
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

        Intent i = new Intent(BROADCAST_UPDATE);
        i.putExtra(RECOGNITION_RESULT, result);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
        manager.sendBroadcast(i);
    }

}
项目:SensingKit-Android    文件:SKActivity.java   
private DetectedActivity getActivity(ActivityRecognitionResult result) {

        // Get the most probable activity from the list of activities in the result
        DetectedActivity mostProbableActivity = result.getMostProbableActivity();

        // If the activity is ON_FOOT, choose between WALKING or RUNNING
        if (mostProbableActivity.getType() == DetectedActivity.ON_FOOT) {

            // Iterate through all possible activities. The activities are sorted by most probable activity first.
            for (DetectedActivity activity : result.getProbableActivities()) {

                if (activity.getType() == DetectedActivity.WALKING || activity.getType() == DetectedActivity.RUNNING) {
                    return activity;
                }
            }

            // It is ON_FOOT, but not sure if it is WALKING or RUNNING
            Log.i(TAG, "Activity ON_FOOT, but not sure if it is WALKING or RUNNING.");
            return mostProbableActivity;
        }
        else
        {
            return mostProbableActivity;
        }

    }
项目:android_sensor_logger    文件:ActivityRecognitionIntentService.java   
/**
 * Called when a new activity detection update is available.
 */
@Override
protected void onHandleIntent(Intent intent) {
    //...
    // If the intent contains an update
    if (ActivityRecognitionResult.hasResult(intent)) {
        // Get the updatenex
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

        DetectedActivity mostProbableActivity = result.getMostProbableActivity();

        // Get the confidence % (probability)
        int confidence = mostProbableActivity.getConfidence();

        // Get the type
        int activityType = mostProbableActivity.getType();

        Intent sendToLoggerIntent = new Intent("com.pinsonault.androidsensorlogger.ACTIVITY_RECOGNITION_DATA");
        sendToLoggerIntent.putExtra("Activity", activityType);
        sendToLoggerIntent.putExtra("Confidence", confidence);
        sendBroadcast(sendToLoggerIntent);
    }
}
项目:Android_TWWB    文件:TwwbRecognition.java   
@Override
public void onHandleIntent(Intent intent) {
    if (DEBUG) Log.d(TAG, "onHandleIntent: intent="+intent);
    if (!ActivityRecognitionResult.hasResult(intent)) {
        return;
    }

    ActivityRecognitionResult arr = ActivityRecognitionResult.extractResult(intent);
    DetectedActivity mpa = arr.getMostProbableActivity();

    Intent i = new Intent(Constants.ACTION_RECOGNITION);
    i.putExtra(Constants.EXTRA_TYPE,       mpa.getType());
    i.putExtra(Constants.EXTRA_CONFIDENCE, mpa.getConfidence());

    LocalBroadcastManager.getInstance(this).sendBroadcast(i);
}
项目:maps-android-codelabs    文件:ActivityRecognitionIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (intent.getAction() != LocationActivity.ACTION_ACTIVITY_RECOGNITION) {
        return;
    }
    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult
                .extractResult(intent);
        DetectedActivity detectedActivity = result
                .getMostProbableActivity();
        int activityType = detectedActivity.getType();

        Log.v(LocationActivity.TAG, "activity_type == " + activityType);

        // Put the activity_type as an intent extra and send a broadcast.
        Intent send_intent = new Intent(
                LocationActivity.ACTION_ACTIVITY_RECOGNITION);
        send_intent.putExtra("activity_type", activityType);
        sendBroadcast(send_intent);
    }
}
项目:maps-android-codelabs    文件:ActivityRecognitionIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (intent.getAction() != LocationActivity.ACTION_ACTIVITY_RECOGNITION) {
        return;
    }
    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult
                .extractResult(intent);
        DetectedActivity detectedActivity = result
                .getMostProbableActivity();
        int activityType = detectedActivity.getType();

        Log.v(LocationActivity.TAG, "activity_type == " + activityType);

        // Put the activity_type as an intent extra and send a broadcast.
        Intent send_intent = new Intent(
                LocationActivity.ACTION_ACTIVITY_RECOGNITION);
        send_intent.putExtra("activity_type", activityType);
        sendBroadcast(send_intent);
    }
}
项目:maps-android-codelabs    文件:ActivityRecognitionIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (intent.getAction() != LocationActivity.ACTION_ACTIVITY_RECOGNITION) {
        return;
    }
    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult
                .extractResult(intent);
        DetectedActivity detectedActivity = result
                .getMostProbableActivity();
        int activityType = detectedActivity.getType();

        Log.v(LocationActivity.TAG, "activity_type == " + activityType);

        // Put the activity_type as an intent extra and send a broadcast.
        Intent send_intent = new Intent(
                LocationActivity.ACTION_ACTIVITY_RECOGNITION);
        send_intent.putExtra("activity_type", activityType);
        sendBroadcast(send_intent);
    }
}
项目:GitHub    文件:ActivityUpdatesObservable.java   
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, Observer<? super ActivityRecognitionResult> observer) {
    receiver = new ActivityUpdatesBroadcastReceiver(observer);
    context.registerReceiver(receiver, new IntentFilter(ACTION_ACTIVITY_DETECTED));
    PendingIntent receiverIntent = getReceiverPendingIntent();
    ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(apiClient, detectionIntervalMilliseconds, receiverIntent);
}
项目:GitHub    文件:ActivityUpdatesObservable.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        observer.onNext(result);
    }
}
项目:Saiy-PS    文件:MotionIntentService.java   
@Override
protected void onHandleIntent(final Intent intent) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "onHandleIntent");
    }

    if (SPH.getMotionEnabled(getApplicationContext())) {

        if (intent != null) {
            if (DEBUG) {
                examineIntent(intent);
            }

            if (ActivityRecognitionResult.hasResult(intent)) {
                final Motion motion = extractMotion(intent);
                if (motion != null) {
                    MotionHelper.setMotion(getApplicationContext(), motion);
                } else {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "onHandleIntent: motion null: ignoring");
                    }
                }
            } else {
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "onHandleIntent: no ActivityRecognition results");
                }
            }
        } else {
            if (DEBUG) {
                MyLog.w(CLS_NAME, "onHandleIntent: intent: null");
            }
        }
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "onHandleIntent: user has switched off. Don't store.");
        }
    }
}
项目:Myna    文件:AwarenessImpl.java   
private void handleResult(@NonNull DetectedActivityResult detectedActivityResult){
    ActivityRecognitionResult ar = detectedActivityResult.getActivityRecognitionResult();
    RecognizedActivityResult result = new RecognizedActivityResult();
    List<DetectedActivity> acts = ar.getProbableActivities();
    result.activities = new RecognizedActivity[acts.size()];
    for(int i = 0; i < acts.size(); ++i){
        DetectedActivity act = acts.get(i);
        result.activities[i] = new RecognizedActivity(act.getType(), act.getConfidence());
    }
    resultCallback.onResult(result);
}
项目:truth-android    文件:ActivityRecognitionResultSubject.java   
public static SubjectFactory<ActivityRecognitionResultSubject, ActivityRecognitionResult> type() {
  return new SubjectFactory<ActivityRecognitionResultSubject, ActivityRecognitionResult>() {
    @Override
    public ActivityRecognitionResultSubject getSubject(FailureStrategy fs, ActivityRecognitionResult that) {
      return new ActivityRecognitionResultSubject(fs, that);
    }
  };
}
项目:assistance-platform-client-sdk-android    文件:MotionActivitySensor.java   
/**
 * Handles new motion activity data
 *
 * @param userActivityResult
 */
public void handleData(ActivityRecognitionResult userActivityResult) {

    probableActivities = userActivityResult.getProbableActivities();
    mostProbableActivity = userActivityResult.getMostProbableActivity();

    dumpData();
}
项目:gps-measurement-tools    文件:MainActivity.java   
@Override
public void onReceive(Context context, Intent intent) {

  // Modify the status of mRealTimePositionVelocityCalculator only if the status is set to auto
  // (indicated by mAutoSwitchGroundTruthMode).
  if (mAutoSwitchGroundTruthMode) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    setGroundTruthModeOnResult(result);
  }
}
项目:gps-measurement-tools    文件:MainActivity.java   
/**
 * Sets up the ground truth mode of {@link RealTimePositionVelocityCalculator} given an result
 * from Activity Recognition update. For activities other than {@link DetectedActivity#STILL}
 * and {@link DetectedActivity#TILTING}, we conservatively assume the user is moving and use the
 * last WLS position solution as ground truth for corrected residual computation.
 */
private void setGroundTruthModeOnResult(ActivityRecognitionResult result){
  if (result != null){
    int detectedActivityType = result.getMostProbableActivity().getType();
    if (detectedActivityType == DetectedActivity.STILL
        || detectedActivityType == DetectedActivity.TILTING){
      mRealTimePositionVelocityCalculator.setResidualPlotMode(
          RealTimePositionVelocityCalculator.RESIDUAL_MODE_STILL, null);
    } else {
      mRealTimePositionVelocityCalculator.setResidualPlotMode(
          RealTimePositionVelocityCalculator.RESIDUAL_MODE_MOVING, null);
    }
  }
}
项目:CoachTracker    文件:ActivityRecognizerImpl.java   
/**
 * Called when a new activity detection update is available.
 */
@Override
protected void onHandleIntent(final Intent intent) {
    if (ActivityRecognitionResult.hasResult(intent)) {
        new Handler(getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                activityRecognizerListener.onActivityRecognized(
                        ActivityType.values()[ActivityRecognitionResult.extractResult(intent).getMostProbableActivity().getType()]
                );
            }
        });
    }
}
项目:react-native-activity-recognition    文件:DetectionService.java   
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    Log.d(TAG, "Detected activities:");
    for (DetectedActivity da: detectedActivities) {
        Log.d(TAG, getActivityString(da.getType()) + " (" + da.getConfidence() + "%)");
    }

    Intent localIntent = new Intent(BROADCAST_ACTION);
    localIntent.putExtra(ACTIVITY_EXTRA, detectedActivities);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}
项目:ActivityMapper    文件:DetectedActivitiesIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    if (LocationTrackingService.isRunning()) {
        LocationTrackingService.get().locationManager().onActivitiesDetected(result);
    }
}
项目:ActivityMapper    文件:LocationManager.java   
public void onActivitiesDetected(ActivityRecognitionResult recognitionResult) {
    // if you tilt the phone, this will come through, ignore it
    if (onlyTilting(recognitionResult.getProbableActivities())) {
        return;
    }

    if (_detectedActivitiesCache.size() == 5) {
        _detectedActivitiesCache.remove(0);
    }
    _detectedActivitiesCache.add(recognitionResult);
}
项目:googleplayAPI    文件:DetectedActivitiesIntentService.java   
/**
 * Handles incoming intents.
 *
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@Override
protected void onHandleIntent(Intent intent) {
    int currentActivity = DetectedActivity.UNKNOWN;
    //get the message handler
    Messenger messenger = null;
    Bundle extras = intent.getExtras();
    if (extras != null) {
        messenger = (Messenger) extras.get("MESSENGER");
    }
    //get the activity info
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

    //get most probable activity
    DetectedActivity probably = result.getMostProbableActivity();
    if (probably.getConfidence() >= 50) {  //doc's say over 50% is likely, under is not sure at all.
        currentActivity = probably.getType();
    }
    Log.v(TAG, "about to send message");
    if (messenger != null) {
        Message msg = Message.obtain();
        msg.arg1 = currentActivity;
        Log.v(TAG, "Sent message");
        try {
            messenger.send(msg);
        } catch (android.os.RemoteException e1) {
            Log.w(getClass().getName(), "Exception sending message", e1);
        }
    }

}
项目:activity-recognition-example    文件:ActivityRecognitionIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {

    // Get the ActivityRecognitionResult
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

    // Get the list of the probable activities
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    String type = "";
    float confidence = 0;

    // Select the most confidence type
    for (DetectedActivity da : detectedActivities) {
        if (da.getConfidence() > confidence) {
            confidence = da.getConfidence();
            type = Constants.getActivityString(
                    getApplicationContext(),
                    da.getType());
        }
    }

    // Add to the notification the current most confidence activity
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("Current activity: " + type)
                    .setOngoing(true)
                    .setContentText("Confidence: " + String.valueOf(confidence) + "%");
    int mNotificationId = Constants.NOTIFICATION_ID;
    NotificationManager mNotifyMgr =
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mNotifyMgr.notify(mNotificationId, mBuilder.build());
}
项目:dslink-java-android    文件:ActivityRecognitionIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        if (DSContext.CONTEXT != null && DSContext.CONTEXT.activityNode != null) {
            String name = getNameFromType(result.getMostProbableActivity().getType());
            DSContext.CONTEXT.activityNode.setValue(new Value(name));
        }
    }
}
项目:Pandora-sdk-android    文件:ActivityRecognitionIntentService.java   
/** Called when a new activity detection update is available.
 * 
 */
@Override
protected void onHandleIntent(Intent intent){
    if(ActivityRecognitionResult.hasResult(intent)){

        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        // notify   
        AndroidEventBus.getInstance().getBus().post(new AndroidEventMessage(Configuration.NEW_ACTIVITY, result)); 

    }
}
项目:Rejsekort-Reminder    文件:ActivitySensorIntentService.java   
/**
 * Called when a new activity detection update is available.
 */
@Override
protected void onHandleIntent(Intent intent) {
    Log.i("AS Service", "onHandleIntent: Got here!");
    if (ActivityRecognitionResult.hasResult(intent)) {
        // Get the update
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

        DetectedActivity mostProbableActivity = result.getMostProbableActivity();

        // Get the confidence % (probability)
        int confidence = mostProbableActivity.getConfidence();

        // Get the type
        int activityType = mostProbableActivity.getType();

        // process 
        Intent broadcastIntent = new Intent(ACTIVITY_RECOGNITION_DATA);
        broadcastIntent.putExtra(ACTIVITY, activityType);
        broadcastIntent.putExtra(CONFIDENCE, confidence);
        LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);

        Log.i("AS Service","Sent a local broardcast with the activity data.");

    }
    Log.i("AS", "onHandleIntent called");
}
项目:dslink-java-android    文件:ActivityRecognitionIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        if (DSContext.CONTEXT != null && DSContext.CONTEXT.activityNode != null) {
            String name = getNameFromType(result.getMostProbableActivity().getType());
            DSContext.CONTEXT.activityNode.setValue(new Value(name));
        }
    }
}
项目:HereAStory-Android    文件:GameService.java   
@Override
public void onHandleIntent(Intent intent) {
    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        List<DetectedActivity> activities = result.getProbableActivities();

        DetectedActivity bestActivity = null;
        int bestConfidence = 0;

        for (DetectedActivity activity : activities) {
            Log.d(TAG, "Activity " + activity.getType() + " " + activity.getConfidence());
            if (ACTIVITY_MASK.contains(activity.getType())) {
                if (activity.getConfidence() > bestConfidence) {
                    bestActivity = activity;
                    bestConfidence = activity.getConfidence();
                }
            }
        }

        DetectedActivity currentActivity = bestActivity;
        long currentTime = System.currentTimeMillis();
        if (currentActivity == null) {
            Log.w(TAG, "No activity matches!");
            return;
        }
        if (mGameHandler != null && mGameHandler.getLooper().getThread().isAlive()) {
            mGameHandler.sendMessage(
                    mGameHandler.obtainMessage(MESSAGE_ACTIVITY,
                            new ActivityLog(currentActivity, currentTime))
            );
        }
    }
}
项目:MoST    文件:PeriodicGoogleActivityRecognitionInput.java   
@Override
public void onReceive(Context context, Intent intent) {

    if (ActivityRecognitionResult.hasResult(intent)) {
        // Get the update
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        // Get the most probable activity
        DetectedActivity mostProbableActivity = result.getMostProbableActivity();
        int confidence = mostProbableActivity.getConfidence();
        int activityType = mostProbableActivity.getType();
        String activityName = getNameFromType(activityType);

        if (DEBUG)
            Log.i(TAG, String.format("Recognized %s with confidence %d", activityName, confidence));

        DataBundle b = _bundlePool.borrowBundle();
        b.putInt(KEY_CONFIDENCE, confidence);
        b.putString(KEY_RECOGNIZED_ACTIVITY, activityName);
        b.putLong(Input.KEY_TIMESTAMP, System.currentTimeMillis());
        b.putInt(Input.KEY_TYPE, getType().toInt());
        post(b);

        if (_activityRecognitionClient != null && _activityRecognitionClient.isConnected()) {
            _activityRecognitionClient.removeActivityUpdates(_pendingIntent);
            _activityRecognitionClient.disconnect();
            _activityRecognitionClient = null;
        }

    }

}