2013-04-05 87 views
0

我試圖讓包括接近手勢的應用程序,但爲了這個,我需要計數傳感器更新,任何人都可以告訴我一個代碼示例如何算傳感器的更新!的Android - 計數傳感器更新

+0

看看這個教程http://android-er.blogspot.co.il/2011 /09/monitor-proximity-sensor.html ..和下一次不要問同樣的問題兩次.. – Elior 2013-04-05 20:44:17

+1

與@沿繼了Elior的鏈接,只需設置一個全局整型變量,在活動中宣佈它爲0 。然後,在方法onSenserEvent只是增加全局變量。 – dennisdrew 2013-04-05 20:48:38

+0

dennisdrew是對的 – Elior 2013-04-05 20:55:35

回答

0

Decalre在活動的全局變量作爲count_events

private int count_events=0; 

然後在你的onSensorChanged(SensorEvent事件)功能做如下修改:

 public void onSensorChanged(SensorEvent event) { 
     Sensor mySensor=event.sensor; 
     int type=mySensor.getType(); 
     if(type==Sensor.TYPE_PROXIMITY) { 
      count_events++; 
     }