public void runSound(){
Intent it = new Intent(Values.TAG_EXECUTE_ALARM);
PendingIntent pendIntent = PendingIntent.getBroadcast(this, 0, it, 0);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND,0);
AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
long time = calendar.getTimeInMillis();
alarm.set(AlarmManager.RTC_WAKEUP,time,pendIntent);
}
This method is called from a service. My service is supposed to play a sound to notify the user even if the device is on sleep mode.
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
MediaPlayer player = MediaPlayer.create(arg0, R.raw.order_alarm);
player.setAudioStreamType(AudioManager.STREAM_ALARM);
player.start();
}
This is the class that will actually play the sound. Unfortunately the devices doesn't wake up and the sound is not played. When runSound is called before the device enters in sleep mode the sound works perfecly... Any ideas?
Edit:
-> Removed static references (yes, they were dumb, since runSound is inside a service).
-> Yes, the tag value is defined in receiver intent-filter
-> Improved the question.