2

I dont have an actual Android phone, and i want to test Alarm, but i dont know if its the code that has error, or the emulator doesnt do the way like an actual phone in terms of booting.

the Autostart Code is from here: Alarm Manager Example

The code doesnt give me error, the simple alarm manager and service is OK, but the autostart of the alarm is not working, i hope its only on the emu, wish it will work in an actual phone. The code below is from the above-mentioned thread, and it also the one that i uses.. i'd put it because maybe the code are the problems

Manifest

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
...
<receiver android:name=".AutoStart">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"></action>
    </intent-filter>
</receiver>
...

And this is the on-boot trigger

package YourPackage;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class AutoStart extends BroadcastReceiver
{   
    Alarm alarm = new Alarm();
    @Override
    public void onReceive(Context context, Intent intent)
    {   
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
        {
            alarm.SetAlarm(context);
        }
    }
}
Community
  • 1
  • 1
mcr619619
  • 435
  • 1
  • 4
  • 13

3 Answers3

1

Go to the "platform-tools" folder in your "android-sdk" folder through command line. Type following commands:

adb devices

-- Here it will list the current emulator you have started earlier. If the emulator is dislayed, which will, then type below command.

adb reboot

-- This will reboot the emulator without touching any button on on the emulator.

Gaurav Navgire
  • 780
  • 5
  • 17
  • 29
  • after i execute adb reboot, nothing happens, though the cmd doesnt create a new line and the emulator stops working...maybe its still processing? is restarting it takes long? – mcr619619 Nov 09 '12 at 08:51
1

adb -e shell am broadcast -a android.intent.action.BOOT_COMPLETED

type this, after going to android sdk/platform-tools through command line

this will send an artificial BOOT_COMPLETED action

mcr619619
  • 435
  • 1
  • 4
  • 13
0

You can long press powerOff button which is provided in Emulator then it will show you different options like Silent Mode,Airplane Mode, Power Off. In other case you can restart your emulator. This way you can check your BOOT_COMPLETED broadcast.

Juned
  • 6,290
  • 7
  • 45
  • 93
  • how can i restart it? just close the emu and start it again? the Boot_completed broadcast doesnt work in this case.. – mcr619619 Nov 09 '12 at 08:06
  • 1
    where your application is get installed on internal or external? and add `android:enabled="true"` in your receiver. – Juned Nov 09 '12 at 09:43
  • Its ok now, i use the "adb -e shell am broadcast -a android.intent.action.BOOT_COMPLETED"..thanks anyway – mcr619619 Nov 09 '12 at 10:07
  • 1
    @mcr619619 you should answer to your own question so question could be close – Juned Nov 09 '12 at 11:36