使用我的Android設備如何檢測用戶是否正在步行,騎車或駕車? 我檢查了Google Fit app.它區分跑步,騎車和駕駛。我很困惑我應該用什麼算法來區分這些活動。我知道我將不得不使用加速計傳感器。但我仍然無法區分這些活動。使用Android檢測用戶活動(跑步,騎車,駕駛)
10
A
回答
10
您可以爲此使用GooglePlayServices。
它爲ActivityRecognition提供了特殊的API,它爲每個用戶返回了用戶活動的置信度。
http://developer.android.com/training/location/activity-recognition.html
2
您可以使用DetectActivity來區分預定義的活動類型。
13
這個問題是很老,但因爲有新的技術都在那裏,我認爲這是值得一提的是,如果有人仍然遇到此問題。
我能想出3個選項:
- 您可以實現自己的檢測步行,駕車,騎車技巧 - 用Activity recognition和receiving location updates,雖然我建議不要這樣做,不重新發明輪子,已經有很好的發展,現在是2016年。
您可以使用免費的sdk Neura,當您的用戶開始/完成駕駛,開始/結束步行,開始/結束運行,read more of the events you can get from Neura時,它可以向您發送活動。
檢查了這個git project:基本上,該項目有Nuera可以檢測到的所有事件。只需參加這個項目並使其成爲您自己的項目非常簡單。
我強烈推薦使用這個Neura sdk選項。
您可以使用谷歌的FenceApi爲了宣佈柵欄。例如,這是用於檢測駕駛圍欄的代碼。
儘管這種方法看起來不錯,但我已經面對這樣一個事實,即當事件發生時,這個api並沒有告訴我,有時候我開始走路/跑步時花了很長時間,當api告訴我那個事件。
a。包括依賴於你的應用程序的文件的build.gradle:
compile 'com.google.android.gms:play-services-location:+' compile 'com.google.android.gms:play-services-contextmanager:+'
灣清單定義:
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.awareness.API_KEY" android:value="PUT_YOUR_AWARENESS_KEY_HERE" /> <activity android:name=".MainActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
PUT_YOUR_AWARENESS_KEY_HERE:你需要生成一個密鑰here。
c。你MainActivity類別 - 解釋連接到代碼:
public class MainActivity extends Activity { private GoogleApiClient mGoogleApiClient; private PendingIntent mPendingIntent; private FenceReceiver mFenceReceiver; // The intent action which will be fired when your fence is triggered. private final String FENCE_RECEIVER_ACTION = BuildConfig.APPLICATION_ID + "FENCE_RECEIVER_ACTION"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build(); mGoogleApiClient.connect(); // Set up the PendingIntent that will be fired when the fence is triggered. mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(FENCE_RECEIVER_ACTION), 0); // The broadcast receiver that will receive intents when a fence is triggered. mFenceReceiver = new FenceReceiver(); registerReceiver(mFenceReceiver, new IntentFilter(FENCE_RECEIVER_ACTION)); createFence(DetectedActivityFence.IN_VEHICLE, "InVehicleFence"); } @Override public void onDestroy() { try { unregisterReceiver(mFenceReceiver); //Don't forget to unregister the receiver } catch (Exception e) { e.printStackTrace(); } super.onDestroy(); } private void createFence(int detectedActivityFence, final String fenceKey) { AwarenessFence fence = DetectedActivityFence.during(detectedActivityFence); // Register the fence to receive callbacks. Awareness.FenceApi.updateFences( mGoogleApiClient, new FenceUpdateRequest.Builder().addFence(fenceKey, fence, mPendingIntent) .build()).setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { if (status.isSuccess()) { Log.i(getClass().getSimpleName(), "Successfully registered."); } else { Log.e(getClass().getSimpleName(), "Could not be registered: " + status); } } }); } // Handle the callback on the Intent. public class FenceReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { FenceState fenceState = FenceState.extract(intent); switch (fenceState.getCurrentState()) { case FenceState.TRUE: Log.i(fenceState.getFenceKey(), "Active"); break; case FenceState.FALSE: Log.i(fenceState.getFenceKey(), "Not Active"); break; } } } }
此示例是僅用於檢測行駛狀態,但是,你可以叫「createFence」與其他活性的方法,如:
createFence(DetectedActivityFence.TILTING, "TiltingFence"); createFence(DetectedActivityFence.WALKING, "WalkingFence"); createFence(DetectedActivityFence.ON_FOOT, "OnFootFence"); createFence(DetectedActivityFence.RUNNING, "RunningFence");
相關問題
- 1. 使用NUnit駕駛NDepend
- 2. 計算加速度(駕駛汽車)
- 3. 我們可以獲取各種活動的數據嗎?用戶在做跑步,散步,游泳,騎自行車等活動?
- 4. 自動駕駛模式的應用
- 5. iOS:沒有GPS,是否有可能檢測到用戶是否在駕駛車輛?
- 6. 使用JavaScript/CSS3進行橫幅廣告的車輛駕駛前進動畫
- 7. 使用Mapstraction創建駕駛方向和計算駕駛距離的文檔
- 8. 檢測用戶活動
- 9. 尋找跑步活動
- 10. 從UITabBarController駕駛UIImagePickerController
- 11. 表單沒有行動 - >使用自動駕駛儀發佈
- 12. 三星啓用禁用「駕駛模式」
- 13. 如何測量步行或使用Android慢跑時的步驟?
- 14. 如何在使用HERE android SDK駕駛時獲得路標?
- 15. 使用android上的航點繪製駕駛路線
- 16. DataAnnotations駕駛客戶端驗證問題
- 17. 可以我用mongodb的C#駕駛員
- 18. 如何實現自動駕駛儀
- 19. jQuery的facebox不與動態駕駛Ajaxtabs
- 20. 超時硒,動態和即駕駛員
- 21. 駕駛員便攜性
- 22. 再次駕駛IBM-Watson-cognitive
- 23. XA Datasource和駕駛艙
- 24. 駕駛距離的REST API?
- 25. 檢測用戶活動windows phone 8
- 26. Android - 如何在駕駛模式中啓用Google地圖意圖?
- 27. 使用線程騎自行車圖像
- 28. 使用javascript騎自行車圖像
- 29. 如何檢測用戶是否正在用他的設備行走/跑步?
- 30. 使用PHP計算駕車路線?
聽起來不錯。是否有最低的API級別要求,或者只有play服務庫才能完成工作? – 2014-11-21 10:43:26
@MayurMore它支持從android 2.2開始...... – 2014-11-21 12:12:26
這兩個鏈接現在指向其他東西 – 2015-07-23 16:07:12