Erel Hansav
Erel Hansav

Reputation: 71

android show activity when phone sleep

I have a broadcast receiver who's job is to open an Activity. (Specifically when i receive a certain SMS). When my phone is on and I use it, it works great.
But when my phone is on sleep mode nothing happens.
Do I need to add a code in my broadcast receiver to WAKEUP the phone and release the SCREEN LOCK (if there is) and then open the Activity?
Or is there a better solution?

This is the relevant code in the broadcast receiver onReceive function:

    //Create a new PendingIntent and add it to the AlarmManager
Intent intent = new Intent(context, Alarm.class);
intent.putExtra("coordinates", coordinates);
PendingIntent pendingIntent = PendingIntent.getActivity(context,
    0, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager am = (AlarmManager)context.getSystemService(Activity.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 100, pendingIntent);

Upvotes: 0

Views: 2022

Answers (1)

Booger
Booger

Reputation: 18725

You will need to use a WakeLock to accomplish this.

This particular tutorial helped me with this: http://it-ride.blogspot.com/2010/10/android-implementing-notification.html

and another better tutorial specifically about wakelocks: https://github.com/commonsguy/cwac-wakeful

Upvotes: 1

Related Questions