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


Java ActivityRecognitionResult.getProbableActivities方法代碼示例

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


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

示例1: onReceive

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
@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
}
 
開發者ID:QuintechDevOps,項目名稱:cordova-plugin-quintech-background-geolocation,代碼行數:25,代碼來源:ActivityRecognitionLocationProvider.java

示例2: onHandleIntent

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
/**
 * 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() + "%"
        );
    }
}
 
開發者ID:JimSeker,項目名稱:googleplayAPI,代碼行數:31,代碼來源:DetectedActivitiesIntentService.java

示例3: onNewIntent

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
@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()));

        }
    }
}
 
開發者ID:JimSeker,項目名稱:googleplayAPI,代碼行數:22,代碼來源:MainActivity.java

示例4: onReceive

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
@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
}
 
開發者ID:pmwisdom,項目名稱:cordova-background-geolocation-services,代碼行數:25,代碼來源:BackgroundLocationUpdateService.java

示例5: onHandleIntent

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:alexdao,項目名稱:footstep,代碼行數:30,代碼來源:DetectedActivitiesIntentService.java

示例6: onHandleIntent

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:InspectorIncognito,項目名稱:androidApp,代碼行數:27,代碼來源:DetectedActivitiesIntentService.java

示例7: onHandleIntent

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
/**
 * 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() + "%"
        );
    }
}
 
開發者ID:googlesamples,項目名稱:android-play-location,代碼行數:31,代碼來源:DetectedActivitiesIntentService.java

示例8: getActivity

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
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;
        }

    }
 
開發者ID:SensingKit,項目名稱:SensingKit-Android,代碼行數:27,代碼來源:SKActivity.java

示例9: handleResult

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
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);
}
 
開發者ID:TalkingData,項目名稱:Myna,代碼行數:12,代碼來源:AwarenessImpl.java

示例10: handleData

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
/**
 * Handles new motion activity data
 *
 * @param userActivityResult
 */
public void handleData(ActivityRecognitionResult userActivityResult) {

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

    dumpData();
}
 
開發者ID:Telecooperation,項目名稱:assistance-platform-client-sdk-android,代碼行數:13,代碼來源:MotionActivitySensor.java

示例11: onHandleIntent

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
@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);
}
 
開發者ID:Aminoid,項目名稱:react-native-activity-recognition,代碼行數:15,代碼來源:DetectionService.java

示例12: onHandleIntent

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
@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());
}
 
開發者ID:jamescoggan,項目名稱:activity-recognition-example,代碼行數:35,代碼來源:ActivityRecognitionIntentService.java

示例13: onHandleIntent

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
@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))
            );
        }
    }
}
 
開發者ID:benbek,項目名稱:HereAStory-Android,代碼行數:34,代碼來源:GameService.java

示例14: logActivity

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
private void logActivity(ActivityRecognitionResult result) {
    Log.d(TAG, "Unknown Activity");
    Log.d(TAG, "Probable Activities");
    for(DetectedActivity activity : result.getProbableActivities()) {
        Log.d(TAG, "Most Probable list: " + result.getMostProbableActivity().getType());
        Log.d(TAG, "Most Probable list: " + result.getMostProbableActivity().toString());
    }
    Log.d(TAG, "Most Probable: " + result.getMostProbableActivity().getType());
    Log.d(TAG, "Most Probable: " + result.getMostProbableActivity().toString());
}
 
開發者ID:team-mount-ventoux,項目名稱:JayPS-AndroidApp,代碼行數:11,代碼來源:ActivityRecognitionIntentService.java

示例15: onHandleIntent

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
/**
 * 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();

    SharedPreferences.Editor editor = preferences.edit();

    i = preferences.getInt("FootCount", 0);

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

        if (da.getType() == DetectedActivity.IN_VEHICLE && da.getConfidence() > 90 && !preferences.getBoolean("VehicleNotified", false)) {
            sendNotification();
            editor.putBoolean("VehicleNotified", true);
        }

        if (da.getType() == DetectedActivity.ON_FOOT && da.getConfidence() > 90)
            editor.putInt("FootCount", ++i);
        if (preferences.getInt("FootCount", 0) == 3 && !preferences.getBoolean("FootNotified", false)) {
            sendNotification();
            editor.putBoolean("FootNotified", true);
        }
        editor.commit();
    }

    // Broadcast the list of detected activities.
    localIntent.putExtra(Constants.ACTIVITY_EXTRA, detectedActivities);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}
 
開發者ID:maddygy,項目名稱:Activity-Recognition-Tools,代碼行數:46,代碼來源:DetectedActivitiesIntentService.java


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