简体   繁体   中英

Android: How to create a reminder such as google keep reminder

I want to add a reminder to my android app such as Google Keep app reminder for notes, as you know in Gkeep you can set reminder for your notes by set date (Today,Tomorrow,Next same day or Pick a date from Calendar) and set time (Morning, Afternoon,Evening, Night or pick a time from Clock). Any help?

I found my answer! and share it with you because i think its nothing to do with Mechanical Turk :)). in MainActivity:

final AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
final Intent intentAlarm = new Intent(MainActivity.this, AlarmReceiver.class);
Calendar calendar =  Calendar.getInstance();   
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 22);
calendar.set(Calendar.HOUR, 5);
calendar.set(Calendar.AM_PM, Calendar.PM);
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DAY_OF_MONTH, 6);
calendar.set(Calendar.YEAR,2015);
long when = calendar.getTimeInMillis();
alarmManager.set(AlarmManager.RTC_WAKEUP,when, PendingIntent.getBroadcast(MainActivity.this,1,  intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));

and the AlarmReciver class :

public class AlarmReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Calendar now = GregorianCalendar.getInstance();
            Notification.Builder mBuilder = 
                    new Notification.Builder(context)
                    .setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("my title")
                    .setContentText("my text");             
            Intent resultIntent = new Intent(context, MainActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);
            NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(1, mBuilder.build());
    }
}

And to cancel the reminder :

if (alarmManager!= null) {
                alarmManager.cancel(PendingIntent.getBroadcast(MainActivity.this,1,  intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM