It would help if you could define "unable to set an alarm". On Tue, Apr 19, 2011 at 11:06 AM, Brad Stintson <[email protected]> wrote: > I have set the date and time for the event in the interface using datepicker > and timepicker respectively. > These are stored in the database by converting them into long format. > For retrieval, they can be converted back to calendar format(using the > function getCalendarFromFormattedLong). > The following code is however unable to set an alarm and thus unable to > trigger a timed notification. > > ============================================================= > package org.event.home; > import java.util.Calendar; > import java.util.Date; > import java.util.GregorianCalendar; > import org.event.home.R; > import android.app.Activity; > import android.app.AlarmManager; > import android.app.AlertDialog; > import android.app.PendingIntent; > import android.content.Context; > import android.content.DialogInterface; > import android.content.Intent; > import android.database.Cursor; > import android.os.Bundle; > import android.os.SystemClock; > import android.widget.Toast; > public class AlarmTrig extends Activity { > AlarmManager am; > AlarmManager alarms; > private DBAdapter mDbHelper; > private Intent i; > private Long mEventId; > private Cursor event_retrive; > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.rem_create); > i = getIntent(); > mEventId = i.getExtras().getLong("EVENT_ID"); > > mDbHelper = new DBAdapter(this); > mDbHelper.open(); > > if (mEventId != null) { > > event_retrive = mDbHelper.retrieveEvent(mEventId); > startManagingCursor(event_retrive); > } > > am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); > setOneTimeAlarm(); > } > > public void setOneTimeAlarm() { > long dt = event_retrive.getLong(8); > Calendar d = DateDataFormat.getCalendarFromFormattedLong(dt); > > AlertDialog.Builder builder = new AlertDialog.Builder(this); > builder.setTitle("Title"); > builder.setMessage(""+d); > builder.setNeutralButton("OK", new > DialogInterface.OnClickListener() { > @Override > public void onClick(DialogInterface dialog, int which) { > dialog.dismiss(); > return; > } > }); > AlertDialog alert = builder.create(); > alert.show(); > Intent activate = new Intent(this, TimeAlarm.class); > PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, > activate, 0); > alarms = (AlarmManager)getSystemService(Context.ALARM_SERVICE); > alarms.set(AlarmManager.RTC_WAKEUP, d.getTimeInMillis(), alarmIntent); > } > } > ========================================================================== > Thanking you in advance. > Regards, > Brad > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en
-- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android 3.0 Programming Books: http://commonsware.com/books -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

