So here's the deal... I have a really rough time getting up the morning. An alarm will wake me up, but the problem is, no matter how many barriers to snoozing/disabling an alarm (math problems, etc.) that an alarm clock app has, I just get around it by turning off the phone then going back to sleep. I have been late for many a meeting because of this. I've been meaning to venture intoandroid development for a while, and I thought it would be good to start with creating an alarm clock app that will sound the alarm for a set amount of time, with no snooze/dismiss button, that will prevent the phone from being turned off while the alarm is active. However I'm not sure the last part is possible. Is it?
-
1Similar to http://stackoverflow.com/questions/8036701/how-to-disable-power-button Basically you can't on a standard Android build. You need to flash your ROM and install a custom one (cyanogenMod or other) that implements some access to the power button. – JScoobyCed Sep 05 '13 at 02:56
-
when you finished the app, please post the code or a link to the apk or something. might need it too :) – Keale Sep 05 '13 at 02:59
-
@JScoobyCed, it looks like I can acquire `PowerManager.WakeLock,` but if I understand it correctly, it only prevents the screen from going to sleep, not from turning off the phone completely. Maybe I need to consider physically preventing myself from getting to the power button :P @Keale I'll do that! – corinnaerin Sep 06 '13 at 01:21
2 Answers
It is not possible. There is a good explanation about that here.
However, there is function with which you can detect power key long pressed and is as below:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_POWER)
{
return true;
}
return super.dispatchKeyEvent(event);
}
Using this function, you can at least notify user about the alarm or that the alarm won't work if the phone is switched off!
Also, it is not so good to find out that Android cannot handle alarm if phone is switched off from this issue posted on Android Open Source Project - Issue Tracker. A simple Nokia phone or a Black Berry could do it. I think they should try to implement this feature, as users would not want the battery drained totally when they are sleeping but still would like to wake up with the alarm they have set.

- 1
- 1
I can give you rough idea that may be hep you
1) Create AlramActivity.java
1. set alram
2. Modify Alarm
3. Delete Alarm
2) Create AlarmTriggeredActivity.java
-> This activity will passed as pending intent to alarm service.
-> Calls when alarm triggered.
-> When this Activity calls generate one random mathematical equation like : (Any arithmetic)
1364 * 23
362 / 0.5
-> As alarm triggered this equation will be on screen, Until user solved alarm will not stop.
->Play alarm sound in thread And set high priority of this thread to 10

- 28,348
- 10
- 61
- 77
-
There are already a lot of applications in the Android market that do something similar. I have tried Alarm Clock xTreme (which makes you do math problems before you can dismiss/snooze), and another called I Can't Wake Up which has a lot of different tasks including memory games, captchas, etc. The problem is I quickly get very adept at performing these tasks because they don't take very long, and then I go right back to sleep. That's why I want to create an app that you simply *can't* dismiss/snooze for a set amount of time. – corinnaerin Sep 06 '13 at 01:19