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


Java ActivityRecognitionResult.hasResult方法代碼示例

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


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

示例1: 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);
        }

    }
}
 
開發者ID:kylecorry31,項目名稱:ShutUpAndDrive,代碼行數:25,代碼來源:DetectedActivityIntentService.java

示例2: 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);

	}

}
 
開發者ID:participactunibo,項目名稱:MoST,代碼行數:23,代碼來源:GoogleActivityRecognitionInput.java

示例3: 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();
                }
            }
        }
    }
}
 
開發者ID:rubenlop88,項目名稱:autotracks-android,代碼行數:21,代碼來源:ActivityRecognitionService.java

示例4: 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);
    }

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

示例5: 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");
		}
	}
}
 
開發者ID:LSIR,項目名稱:gsn,代碼行數:40,代碼來源:AndroidActivityRecognitionWrapper.java

示例6: onHandleIntent

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

示例7: onHandleIntent

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

示例8: onHandleIntent

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

示例9: onReceive

import com.google.android.gms.location.ActivityRecognitionResult; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        observer.onNext(result);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:ActivityUpdatesObservable.java

示例10: onHandleIntent

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

示例11: onHandleIntent

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

示例12: onHandleIntent

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

示例13: onHandleIntent

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

示例14: onHandleIntent

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

示例15: 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


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