我寫了一個加速計應用程序(用於學習目的)使用StackOverflow的一些建議。一切工作正常,但我得到了「SensorManager.DATA_X已經過時」消息在我的代碼警告:Android加速度計:SensorManager.DATA_X已棄用 - 現在該怎麼辦?
// setup the textviews for displaying the accelerations
mAccValueViews[SensorManager.DATA_X] = (TextView) findViewById(R.id.accele_x_value);
mAccValueViews[SensorManager.DATA_Y] = (TextView) findViewById(R.id.accele_y_value);
mAccValueViews[SensorManager.DATA_Z] = (TextView) findViewById(R.id.accele_z_value);
我試圖尋找在這裏和其他地方我應該做的,而不是使用「SensorManager.DATA_X」的話,但我似乎無法找到任何指示。
官方指南說,使用「傳感器」,而不是我怎麼搞清楚!
如果任何人都可以建議什麼新的「官方」做上述方法,那麼我將非常感激。
編輯 後重新閱讀文檔(正常這個時候!)我注意到,「SensorManager.DATA_X」只返回一個int這是onSensorChanged返回數組中的X值的索引(INT ,float [])。我能夠改變上面的代碼到這一點,這完美的作品,沒有任何過時的警告:
// setup the textviews for displaying the accelerations
mAccValueViews[0] = (TextView) findViewById(R.id.accele_x_value);
mAccValueViews[1] = (TextView) findViewById(R.id.accele_y_value);
mAccValueViews[2] = (TextView) findViewById(R.id.accele_z_value);
您是否閱讀過文檔:http://developer.android.com/guide/topics/sensors/sensors_overview.html –