Android - How to create a reminder / Alarm in the application

I searched the Internet for an hour trying to figure out how to create a reminder or alarm in the Android app. Does anyone know any tutorials for creating reminders in your Android app?

+7
android alarm
source share
3 answers

To wake up the phone and schedule an alarm, use the AlarmManager. Then transmit the broadcast receiver that receives the alarm, do whatever you want (make noise, vibrate, add notification, etc.).

+5
source share

You can directly use the alarm to set the alarm in the application. Check out the link below: http://developer.android.com/reference/android/provider/AlarmClock.html

Else: Or you can use AlarmManager, here you can see how to install it:

private void setAlarm(){ Context context = getApplicationContext(); AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, OnAlarmReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0); myCal = Calendar.getInstance(); myCal.setTimeInMillis(TIME_THE_ALARM_SHOULD_GO_OFF_AS_A_LONG); mgr.set(AlarmManager.RTC_WAKEUP, myCal.getTimeInMillis(), pi); Log.i(myTag, "alarm set for " + myCal.getTime().toLocaleString()); Toast.makeText(getApplicationContext(),"Alarm set for " + myCal.getTime().toLocaleString(), Toast.LENGTH_LONG).show(); } 
+2
source share

I don’t know what exactly you want to do ... but to play an audible alarm, you can use this:

 Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); 

Also, if you want to receive a notification, follow these steps:

 private static final int MY_NOTIFICATION_ID = 1; private NotificationManager notificationManager; private Notification myNotification; private final String myBlog = "abc"; buttonSend.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); myNotification = new Notification(R.drawable.ic_launcher, "Notification!", System.currentTimeMillis()); Context context = getApplicationContext(); String notificationTitle = "Exercise of Notification!"; String notificationText = "hello"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri .parse(myBlog)); PendingIntent pendingIntent = PendingIntent.getActivity( MainActivity.this, 0, myIntent, Intent.FLAG_ACTIVITY_NEW_TASK); myNotification.defaults |= Notification.DEFAULT_SOUND; myNotification.flags |= Notification.FLAG_AUTO_CANCEL; myNotification.setLatestEventInfo(context, notificationTitle, notificationText, pendingIntent); notificationManager.notify(MY_NOTIFICATION_ID, myNotification); } }); 
+2
source share

All Articles