2012-05-15 6 views
0

나는 임의의 인터벌로 사용자를 떠올리게하는 서비스를하고 있습니다. 이 서비스는 활동에 의해 시작되고 백그라운드에서 서비스로 실행됩니다.전화가 잠 들어있는 동안 소리가납니다.

내가 직면 한 도전은 사용자가 휴대 전화를 잠자기 상태로 둡니다 (빈 화면), 어떤 경우에는 소리가 단순히 재생되지 않는다는 것입니다. 시간이 다되었지만 사운드가 정해진 시간에 재생되지 않거나 사용자가 전화를 깨면 재생됩니다. 여기

는 /** *이 얼마나 많은 시간이 * 경과 모든 초를 확인하고 시간의 포인트는 사운드를 재생하기 위해 오는 경우 새 스레드를 시작하는 코드이다. * 시간이되면 다음 벨소리가 울리고 * 사용자가 종료 할 때까지 계속됩니다. */ private void runCheck() { Log.i (태그, "runCheck 시작");

Thread thread = new Thread() { 
     public void run() { 

      Log.i(tag, "starting LogoTimerThread"); 
      while (vRunningFlag) { 

       try { 

        // update the notification 
        makeNotification(); 

        Log.v(tag, 
          "Next Ring in : [" 
            + helper.TimeCalculator 
              .duration2_hh_MM_SS((vTimerNextRing - System 
                .currentTimeMillis())/1000) 
            + " sec.]"); 

        // check if time has run out 
        if (vTimerNextRing < System.currentTimeMillis()) { 
         // reset the timer 
         setNextRingTime(); 
         // update the screen 
         makeNotification(); 
         // play the sound 
         playLTimerSound(); 
        } 

        sleep(1000); 
       } catch (InterruptedException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

      } 
      Log.i(tag, "finished LogoTimerThread"); 
     } 
    }; 

    thread.start(); 
} 

전체 서비스가 포 그라운드로 설정되어 원격 서비스를 실행하는, 그래서 알림이 서비스의 사용자를 생각 나게 그는 그런 식으로 중지 할 수 있습니다.

일단 playLTimerSound()를 주석 처리하면 타이머가 카운트 다운됩니다. 어떻게 든 스레드는 사운드를 재생하여 멈 춥니 다.

public void playLTimerSound() { 
    Log.i(tag, "playLogoTimerSound - volume:" + vVolume); 
    MediaPlayer mp = MediaPlayer.create(this, R.raw.enterprise); 
    mp.setVolume(2.0f, 2.0f); 
    mp.start(); 
    mp.setOnCompletionListener(new OnCompletionListener() { 
     @Override 
     public void onCompletion(MediaPlayer mp) { 
      // TODO Auto-generated method stub 
      mp.release(); 
     } 
    }); 
} 

죄송합니다 여기에 서식, 여러분이이에 대한 몇 가지 팁을 가질 수 ;-)

답변

0

당신을 SCREEN_DIM_WAKE_LOCK을 aquire 수없는 시나리오 :뿐만 아니라 그 기능 IST 여기

?

@Override 
protected void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 




PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 
wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "App"); 
wl.acquire(); 

} 
+0

사운드를 재생하거나 생성하기 전에 잠금 장치를 확보해야합니까? 나는 wakelocks에 익숙하지 않다. – user929995

관련 문제