Two things:

- don't use getApplicationContext, use the activity

- change the intent for the alarm from using a class to using an action
string

- set up a broadcast receiver to receive the action, with an intent filter
matching the action's string identifier

Oops, that was three...

--
Kostya Vasilyev -- http://kmansoft.wordpress.com

18.08.2010 23:17 пользователь "khushi" <mudratriv...@gmail.com> написал:

Hi,

I am beginner to android development. I want to make an application
for an alarm clock. I want alarm with some predefined ring tones. But
I don't know how to use the existing alarm service. I have written
below code, but it is not running. So can you please suggest me.
Thanks in advance.

My code is like this :


public class AlarmClock extends Activity {

       /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState)
   {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       AlarmManager alarmManager = (AlarmManager)
getSystemService(ALARM_SERVICE);

       Intent intent = new Intent(getApplicationContext(),
OnetimeAlarmReceiver.class);
       PendingIntent pendingIntent =
PendingIntent.getBroadcast(getApplicationContext(), 0, intent,
0x08000000);

       alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(), (5 * 1000), pendingIntent);

       Toast.makeText(getApplicationContext(), "Alarm set",
Toast.LENGTH_LONG).show();

  }

}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to