2012-10-27 3 views
1

나는 백그라운드에서 실행중인 서비스를 가지고 있는데,이 서비스는 새로운 활동 인 RingAlarm을 호출하고 있습니다.서비스 요청시 전화 모으기 Activity and play MediaPlayer, Android

이름처럼이 활동은 알람 플레이어입니다. 그래서 사용자가 버튼을 누를 때까지 소리를냅니다.

화면이 잠겨있을 때를 제외하고 모든 것이 좋았습니다. 그런 다음 그 소리가 들리지 않는다는 것을 발견했습니다.

화면을 가지고 잠금을 해제 내가 이것을 사용하고하려면

PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE); 
    wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); 
    wakeLock.acquire(); 
    KeyguardManager keyguardManager = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); 
    KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG"); 
    keyguardLock.disableKeyguard(); 

을 그리고 내가 이것을 사용하는 ringtoon 재생 : 어쩌면 내가 뭔가 잘못하고 있어요

Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); 
    if(alert == null){ 
     // alert is null, using backup 
     alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     if(alert == null){ // I can't see this ever being null (as always have a default notification) but just incase 
      // alert backup is null, using 2nd backup 
      alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);    
     } 
    } 
    mPlayer = new MediaPlayer(); 
    try { 
     mPlayer.setDataSource(this, alert); 
     mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); 
     mPlayer.setLooping(true); 
     mPlayer.prepare(); 
     mPlayer.start(); 
    } 
    catch(Exception e) { 
    //TODO : Implement Error Checking 
     e.printStackTrace(); 
     Log.e("MediaPlayer", "Error while playing!"); 
    } 

을 ... 어떤 생각?

업데이트 (오류)

10-28 17:49:59.562: I/MediaPlayer(3193): it is a Ringtone type is : 4 
10-28 17:49:59.820: E/RingtoneManager(3193): getActualDefaultRingtoneUri : content://media/internal/audio/media/60 
10-28 17:49:59.820: E/RingtoneManager(3193): Uri.parse(uriString) : content://media/internal/audio/media/60 
10-28 17:49:59.828: I/MediaPlayer(3193): It is a Not a DRM RingTone: return NULl 
10-28 17:49:59.828: I/MediaPlayer(3193): path is null 

나는 여전히 문제가 있습니다. 나는 정말로 그것에 매달렸다. 문제는 미디어 플레이어가 아니라는 것을 알아 냈습니다. 문제는 장치가 잠금 모드에있을 때 응용 프로그램이 다시 시작될 때 제대로하지 않았기 때문에 진동이 작동하지 않는 것입니다.

나는 로그 캣이 경고를 받고 있어요 :

10-29 18:10:07.851: W/IInputConnectionWrapper(19683): getExtractedText on inactive InputConnection 
10-29 18:10:07.851: W/IInputConnectionWrapper(19683): getTextBeforeCursor on inactive InputConnection 
10-29 18:10:07.867: W/IInputConnectionWrapper(19683): getExtractedText on inactive InputConnection 
10-29 18:10:07.867: W/IInputConnectionWrapper(19683): getTextBeforeCursor on inactive InputConnection 
10-29 18:10:07.867: W/IInputConnectionWrapper(19683): getSelectedText on inactive InputConnection 
10-29 18:10:07.875: W/IInputConnectionWrapper(19683): getTextAfterCursor on inactive InputConnection 
10-29 18:10:07.875: W/IInputConnectionWrapper(19683): getExtractedText on inactive InputConnection 
10-29 18:10:07.875: W/IInputConnectionWrapper(19683): getTextBeforeCursor on inactive InputConnection 
10-29 18:10:07.875: W/IInputConnectionWrapper(19683): getSelectedText on inactive InputConnection 
10-29 18:10:07.875: W/IInputConnectionWrapper(19683): getTextAfterCursor on inactive InputConnection 
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): beginBatchEdit on inactive InputConnection 
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): endBatchEdit on inactive InputConnection 
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): getExtractedText on inactive InputConnection 
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): getTextBeforeCursor on inactive InputConnection 
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): getSelectedText on inactive InputConnection 
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): getTextAfterCursor on inactive InputConnection 
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): beginBatchEdit on inactive InputConnection 
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): endBatchEdit on inactive InputConnection 
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): getExtractedText on inactive InputConnection 
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): getTextBeforeCursor on inactive InputConnection 
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): getSelectedText on inactive InputConnection 
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): getTextAfterCursor on inactive InputConnection 

어떤 생각을?

주셔서 감사합니다 Activity

에서

답변

2

해결하려고!

미디어 플레이어 또는 진동을 호출 할 때 화면이 켜지지 않으면 약간의 오류가 발생하고 소리 나 진동이 발생하지 않습니다.

그래서 내가 한 것은 화면이 켜질 때까지 기다리는 asynctask를 만드는 것입니다. 이것이 일어날 때 반지와 진동이 불린다.

그리고 작동합니다!

private class AlarmTask extends AsyncTask<Void, Void, Void> { 

    @Override 
    protected Void doInBackground(Void... arg0) { 
     // TODO Auto-generated method stub 
     while (!window.isActive()) {} 
     if (Preference.readBoolean(getApplicationContext(), Preference.VIBRATION, true)) 
      vibrate(); 
     if (Preference.readBoolean(getApplicationContext(), Preference.SOUND, true)) 
      ring(); 

     return null; 
    } 

} 
1

Window window = this.getWindow(); 
    window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 
    window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); 
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 
+0

이 오류 (게시물의 업데이트를 참조) 화면 잠금이 해제 될 때' – Marcel

+0

코드가' –

+0

예 작동? 노력하지만 오류가 계속 잘 로그 – Marcel