提醒功能 [英] Reminder Functionality

查看:187
本文介绍了提醒功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我想设置的提醒和报警上的提醒,但我不能这样做。

In my application i am trying to set reminder and alarm on that reminder but i am not able to do so.

由于我没有如何设置提醒,编辑和删除其完整和正确的知识。正如我搜索谷歌和我得到的是不容易理解我。

As i don't have complete and proper knowledge of how to set reminder, edit it and delete it. As i searched on google and what i got is not easy to understand for me.

我尝试了code为:Main.java

I tried a code as: Main.java

Calendar cal = Calendar.getInstance();
java.util.Calendar;

// add minutes to the calendar object
cal.set(Calendar.MONTH, 4);
cal.set(Calendar.YEAR, 2011);               
cal.set(Calendar.DAY_OF_MONTH, 5);
cal.set(Calendar.HOUR_OF_DAY, 21);
cal.set(Calendar.MINUTE, 43);

Intent alarmintent = new Intent(getApplicationContext(), AlarmReceiver.class);
alarmintent.putExtra("title","Title of our Notification");
alarmintent.putExtra("note","Description of our  Notification");
//HELLO_ID is a static variable that must be initialised at the BEGINNING OF CLASS with    1;

//example:protected static int HELLO_ID =1;
PendingIntent sender = PendingIntent.getBroadcast(getApplicationContext(), HELLO_ID,
alarmintent,PendingIntent.FLAG_UPDATE_CURRENT|  Intent.FILL_IN_DATA);
//VERY IMPORTANT TO SET FLAG_UPDATE_CURRENT... this will send correct extra's     informations to 
//AlarmReceiver Class
// Get the AlarmManager service

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);

AlarmReceiver.java

AlarmReceiver.java

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver {

    private static int NOTIFICATION_ID = 1;

@Override
public void onReceive(Context context, Intent intent) {

    NotificationManager manger = (NotificationManager)     
    context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.icon, "Combi Note", System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ID, new Intent(context, AlarmReceiver.class), 0);
    Bundle extras=intent.getExtras();
    String title=extras.getString("title");
    //here we get the title and description of our Notification

    String note=extras.getString("note");
    notification.setLatestEventInfo(context, note, title, contentIntent);
    notification.flags = Notification.FLAG_INSISTENT;
    notification.defaults |= Notification.DEFAULT_SOUND;
    //here we set the default sound for our 
    //notification

    // The PendingIntent to launch our activity if the user selects this notification
    manger.notify(NOTIFICATION_ID++, notification);
    }
}

如何设置提醒日历,编辑和删除它们。

How to set reminders in calendar, edit them, and delete them.

感谢你。

推荐答案

我找到答案goggling的,我们可以在Android设备通过访问默认情况下使用事件和提醒设置提醒后。

I found answer after goggling as, we can set reminder in android device by accessing default using EVENTS and Reminder.

在code为如下所示:

The code is as shown:

public void addReminder(int statrYear, int startMonth, int startDay, int startHour, int startMinut, int endYear, int endMonth, int endDay, int endHour, int endMinuts){ 
    Calendar beginTime = Calendar.getInstance();
    beginTime.set(statrYear, startMonth, startDay, startHour, startMinut);
    long startMillis = beginTime.getTimeInMillis();

    Calendar endTime = Calendar.getInstance();
    endTime.set(endYear, endMonth, endDay, endHour, endMinuts);
    long endMillis = endTime.getTimeInMillis();

    String eventUriString = "content://com.android.calendar/events";
    ContentValues eventValues = new ContentValues();

    eventValues.put(Events.CALENDAR_ID, 1);
    eventValues.put(Events.TITLE, "OCS");
    eventValues.put(Events.DESCRIPTION, "Clinic App");
    eventValues.put(Events.EVENT_TIMEZONE, "Nasik");
    eventValues.put(Events.DTSTART, startMillis);
    eventValues.put(Events.DTEND, endMillis);

    //eventValues.put(Events.RRULE, "FREQ=DAILY;COUNT=2;UNTIL="+endMillis);
    eventValues.put("eventStatus", 1);
    eventValues.put("visibility", 3);
    eventValues.put("transparency", 0); 
    eventValues.put(Events.HAS_ALARM, 1);

    Uri eventUri = getContentResolver().insert(Uri.parse(eventUriString), eventValues);
    long eventID = Long.parseLong(eventUri.getLastPathSegment());

    /***************** Event: Reminder(with alert) Adding reminder to event *******************/

    String reminderUriString = "content://com.android.calendar/reminders";

    ContentValues reminderValues = new ContentValues();

    reminderValues.put("event_id", eventID);
    reminderValues.put("minutes", 1);
    reminderValues.put("method", 1);

    Uri reminderUri = getContentResolver().insert(Uri.parse(reminderUriString), reminderValues);
}   

希望这个答案可以帮助设置提醒日历所有。

Hope this answer helps to set reminder in calendar to all.

这篇关于提醒功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆