get phone off sleep in receiver

812 views Asked by At

My app needs to play a ringtone if an sms is coming in (broadcastreceiver). It's functioning correctly if my phone is on. But in sleep the SMS is coming in and nothing is happening. If I get the phone from standby...my ringtone is playing....

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
 PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
 wl.acquire();
   .. play the ringtone and do other actions..
 wl.release();

in the manifest I putted also:

<uses-permission android:name="android.permission.WAKE_LOCK" />

Does anybody know what I'm missing?!

1

There are 1 answers

0
user1404924 On BEST ANSWER

The phone is reacting at a Textmssage with a broadcast receiver. In de broadcast receiver I just start an activity

In that activity (new class) I put the OnCreate:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.niceapp);

    //if phone is in on sleep ...wake him up
    AlarmAlertWakeLock.acquireCpuWakeLock(this);

In the OnStop I put:

    AlarmAlertWakeLock.releaseCpuLock();

That worked for me.