Reputation: 71
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
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