本文整理匯總了Java中com.google.android.gms.location.ActivityRecognitionResult類的典型用法代碼示例。如果您正苦於以下問題:Java ActivityRecognitionResult類的具體用法?Java ActivityRecognitionResult怎麽用?Java ActivityRecognitionResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ActivityRecognitionResult類屬於com.google.android.gms.location包,在下文中一共展示了ActivityRecognitionResult類的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() + "%"
);
}
}
示例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()));
}
}
}
示例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);
}
示例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);
}
示例7: messageAvailable
import com.google.android.gms.location.ActivityRecognitionResult; //導入依賴的package包/類
@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);
}
}
}
示例8: 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() + "%"
);
}
}
示例9: onHandleIntent
import com.google.android.gms.location.ActivityRecognitionResult; //導入依賴的package包/類
@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);
}
}
}
示例10: onReceive
import com.google.android.gms.location.ActivityRecognitionResult; //導入依賴的package包/類
@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);
}
}
示例11: onHandleIntent
import com.google.android.gms.location.ActivityRecognitionResult; //導入依賴的package包/類
@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();
}
}
}
}
}
示例12: isMoving
import com.google.android.gms.location.ActivityRecognitionResult; //導入依賴的package包/類
/**
* 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;
}
示例13: onHandleIntent
import com.google.android.gms.location.ActivityRecognitionResult; //導入依賴的package包/類
@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);
}
}
示例14: 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;
}
}
示例15: runOnce
import com.google.android.gms.location.ActivityRecognitionResult; //導入依賴的package包/類
@Override
public void runOnce() {
if (!isRunning()) {
disconnectGoogleAPI();
} else {
if (mGoogleApiClient == null) {
connectGoogleAPI();
}
updateWrapperInfo();
if (ActivityRecognitionResult.hasResult(ActivityRecognitionService.getIntent())) {
// Get the update
ActivityRecognitionResult result =
ActivityRecognitionResult.extractResult(ActivityRecognitionService.getIntent());
DetectedActivity mostProbableActivity
= result.getMostProbableActivity();
// Get the confidence % (probability)
double confidence = mostProbableActivity.getConfidence();
// Get the type
double activityType = mostProbableActivity.getType();
/* types:
* DetectedActivity.IN_VEHICLE
* DetectedActivity.ON_BICYCLE
* DetectedActivity.ON_FOOT
* DetectedActivity.STILL
* DetectedActivity.UNKNOWN
* DetectedActivity.TILTING
*/
StreamElement streamElement = new StreamElement(FIELD_NAMES, FIELD_TYPES,
new Serializable[]{activityType, confidence});
postStreamElement(streamElement);
} else {
Log.d(TAG, "No results for AndroidActivityRecognition");
}
}
}