M Vignesh
M Vignesh

Reputation: 1646

AlarmManager.RTC_WAKEUP not wakes up my android devices when it is switched off

I have used below code to schedule an alarm in my android application.

/**
     * To set the alarm service to be fire on OFF mode
     */
    public void setOffModeAlarmService() {
        int offModeStartHour = 8;
        int offModeStartMinute = 30;

        Calendar offModeTime = Calendar.getInstance();
        offModeTime.setTimeZone(TimeZone.getTimeZone(Constants.TIME_ZONE));
        offModeTime.set(Calendar.HOUR_OF_DAY, offModeStartHour);
        offModeTime.set(Calendar.MINUTE, offModeStartMinute);

        mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                offModeTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
                getOffModeAlarmPendingIntent());
        mAppUtilInstance.logDebugMessage(TAG, "OFF Mode Alarm Scheduled.");
    }

I scheduled an alarm for every day. But If switch off my mobile some time before of alarm time, then My mobile is not waking up at the scheduled time.

Even I tried using WakefulBroadcastReceiver and also acquired the WakeLock. But nothing helps.

Please help me on this.

Upvotes: 2

Views: 1578

Answers (2)

Hussainmd774
Hussainmd774

Reputation: 3

RTC_WAKEUP playing ringtone when screen off in the emulater, but when i run the apk file in real device it's not playing ringtone in screen off. When i unlock the device it's getting triggered and started playing ringtone. I wonder why it is happening in real device.

public class MyReceiver extends BroadcastReceiver  {
    MediaPlayer mMediaPlayer;


    @Override
    public void onReceive(Context context, Intent intent) {
        mMediaPlayer = new MediaPlayer();

        Uri mediaPath = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.myringtone);
        final MediaPlayer ringtone = MediaPlayer.create(context, mediaPath);
        mMediaPlayer.setLooping(true);
        ringtone.start();

    }

}

Upvotes: 0

Er Robinhood Maurya
Er Robinhood Maurya

Reputation: 102

No, if the phone is off, it can't do anything. If it's in sleep mode where the screen is off and it's not in use then the alarm will still function as will other types of notifications.

On old phones (like nokias) the alarm still rings when the phone is turned off. that's disappointing in android

Upvotes: 2

Related Questions