문제

Couple of days back, I made my first app on Android. The basic concept is to monitor the proximity sensor, if there is an obstacle at the sensor I will increment a counter. If the counter crosses the threshold I will trigger an action.

I have implemented the sensor monitoring SW in a service, this service is called from an Activity in every 10 Min so as awake the cpu and start the service if it is stopped.

Everything was perfect, got few thousands of downloads in market with good ratings. This was fine until Android 2.3.3. Recently my mobile got upgraded to Android 2.3.6 and unfortunately the app is not working as expected.

Sensor listener does not trigger when the screen is OFF. Some times it works fine, most of the times it is not working. After giving several inputs at the sensor, after a while if I switch ON the screen, automatically all the triggers at the sensor are called at once and the counter increments and triggers the action.

To summarize, sensor listener does not work when screen goes OFF (in Android 2.3.6), this was working fine until Android 2.3.3. If I connect the debugger, phone does not go to sleep and everything works fine so I am not able to find the problem. Please help me .

Here is my code .

Calling the service at every 10 min ..

Thread trd = new Thread(){
      public void run(){
        int sec = 1000;
        int min = 60 * sec;
        Calendar cal = Calendar.getInstance();
        alarmMngr.setRepeating(AlarmManager.RTC_WAKEUP, 
                               cal.getTimeInMillis(), 
                       10 * min, 
                       PendInt);
      }
    };
    trd.start();

In the service ..

// On sensor change
public void onSensorChanged(SensorEvent event){
    if(event.sensor == SnsrProx){
       if(event.values[0] <= 5){
           IncProxCntr(1);
       }else{
        IncProxCntr(0);
       }

    } 
}


private void IncProxCntr(int x){
 if( x == 1){
     FakeCall_SnsrCnt++;
     vibrate(VIBRATE_SHORT);
 }
 if(FakeCall_SnsrCnt >= Settings.getMaxSnsrCnts(this)){
 Trig_IncominCall();
 }
}
도움이 되었습니까?

해결책

Acquire wakelock in the service also

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top