title: Wake up phone when service call Activity and play MediaPlayer, Android
body: <p>I have a service that is running on background, in some moment this service is calling a new activity RingAlarm.</p>
  
  <p>Like the name say, this activity is an alarm player. So it plays a sound until the user press the button. </p>
  
  <p>Everything was good, except when I try it when the screen was lock. Then I discovered that the sound was not playing.</p>
  
  <p>To take the screen and unlock it I'm using this:</p>
  
  <pre><code>    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();
  </code></pre>
  
  <p>And to play the ringtoon I use this:</p>
  
  <pre><code>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!");
       }
  </code></pre>
  
  <p>Maybe I'm doing something wrong... any idea?</p>
  
  <p><strong>Update (error)</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p>I still have the problem. I'm really stuck with that.
  I figured out that the problem is not the media player, the problem is that when the device is in lock mode, when the application start again it didn't do it properly, cause the vibration is not working either. </p>
  
  <p>I'm getting this warnings in the logcat:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Any idea?</p>
  
  <p>thanks</p>