-2

I am developing an Alarm application.

I have set the Alarm for particular time. NOW PROBLEM IS:

If mobile is already turned ON then alarm ring.

But if mobile is switched off then not. Requirement:

So, I want to power ON mobile phone and then ring the Alarm If it possible then please share.

Thank you.

Ashish
  • 101
  • 9
  • So, your requirement is to run your alarm when the phone is switched OFF ? – Raptor Apr 09 '14 at 05:43
  • 1
    paste your code here dear – Bhanu Sharma Apr 09 '14 at 05:44
  • 2
    @malvika dear how in this world can you start your device programmatically..? to start device you need to perform the magic of pressing the power on button by yourself using your physical arms...and no program in world will be able to do that for you for obvious reason program needs power and memory to execute and both are unavailable when your device is in power off mode... – Yogesh D Apr 09 '14 at 06:27
  • 2
    @malvika Question you have asked and answer you have accepted looks different... May be you need to rephrase your question... – Gopal Gopi Apr 09 '14 at 07:08

5 Answers5

2

Its not possible,as when the device is switched off your application will not be in running state thus it will not be able to make your Alarm go off neither will be able to switch on your Device but you can do one thing as soon as your device restarts again you can show Alarm Notification at that time

codeRider
  • 685
  • 1
  • 5
  • 14
1

It's not possible to programmatically boot a device up when its turned off.

FD_
  • 12,947
  • 4
  • 35
  • 62
1

At first glance it seems easy. You request this permission the manifest:

<uses-permission android:name="android.permission.REBOOT"/>

And do this:

// Does NOT work must be a system app
void reboot(Context context) {
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    pm.reboot(null);
}

or

try {
  Runtime.getRuntime().exec("su");
  Runtime.getRuntime().exec("reboot");
 } catch (IOException e) {
}  

but your device needs to be rooted.

Harshit Rathi
  • 1,862
  • 2
  • 18
  • 25
  • but first i have to start my androd device progrmaticaly so my question i want a code to start my android device programaticaly – Ashish Apr 09 '14 at 05:54
  • sorry but i dont want to reboot my phone i want to start my phone and both are diffrent reboot-start – Ashish Apr 09 '14 at 06:17
  • then you can't start your device/phone but you can do when when startup your phone once. – Harshit Rathi Apr 09 '14 at 06:19
1

Step 1: First you need a rooted device for the same,

for this: you can follow this link: How rooting is achieved programmatically?

Step 2:

You cannot do a reboot from an ordinary SDK application. Only applications signed with the system firmware signing key can do this.

Programmatically switching off Android phone

you can also try this code for rrotes device.

public void restart(int delay) {
    PendingIntent intent = PendingIntent.getActivity(this.getBaseContext(), 0, new Intent(getIntent()), getIntent().getFlags());
    AlarmManager manager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    manager.set(AlarmManager.RTC, System.currentTimeMillis() + delay, intent);
    System.exit(2);
}
Community
  • 1
  • 1
Lavekush Agrawal
  • 6,040
  • 7
  • 52
  • 85
1

You can show the notification to user "Missed alarm" like default alarm application shows after phone restart. You can use BroadcastReceiver to after BOOT_COMPLETED .

this will help you
http://blog.vogella.com/2011/12/11/automatically-starting-services-in-android-after-booting/

Mahendra
  • 323
  • 2
  • 16