android自定义提示信息吗,如何在Android中设置提醒?

不,如果你想透明地将它添加到用户的日历中,它比调用方法更复杂。

你有几个选择;

调用意图在日历上添加事件

这将弹出日历应用程序并让用户添加事件。您可以将一些参数传递给预填充字段:

Calendar cal = Calendar.getInstance();

Intent intent = new Intent(Intent.ACTION_EDIT);

intent.setType("vnd.android.cursor.item/event");

intent.putExtra("beginTime", cal.getTimeInMillis());

intent.putExtra("allDay", false);

intent.putExtra("rrule", "FREQ=DAILY");

intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);

intent.putExtra("title", "A Test Event from android app");

startActivity(intent);

或者更复杂的一个:

使用此方法获取对日历的引用

(强烈建议不要使用此方法,因为它可能会破坏较新的Android版本):

private String getCalendarUriBase(Activity act) {

String calendarUriBase = null;

Uri calendars = Uri.parse("content://calendar/calendars");

Cursor managedCursor = null;

try {

managedCursor = act.managedQuery(calendars, null, null, null, null);

} catch (Exception e) {

}

if (managedCursor != null) {

calendarUriBase = "content://calendar/";

} else {

calendars = Uri.parse("content://com.android.calendar/calendars");

try {

managedCursor = act.managedQuery(calendars, null, null, null, null);

} catch (Exception e) {

}

if (managedCursor != null) {

calendarUriBase = "content://com.android.calendar/";

}

}

return calendarUriBase;

}

并以这种方式添加事件和提醒:

// get calendar

Calendar cal = Calendar.getInstance();

Uri EVENTS_URI = Uri.parse(getCalendarUriBase(this) + "events");

ContentResolver cr = getContentResolver();

// event insert

ContentValues values = new ContentValues();

values.put("calendar_id", 1);

values.put("title", "Reminder Title");

values.put("allDay", 0);

values.put("dtstart", cal.getTimeInMillis() + 11*60*1000); // event starts at 11 minutes from now

values.put("dtend", cal.getTimeInMillis()+60*60*1000); // ends 60 minutes from now

values.put("description", "Reminder description");

values.put("visibility", 0);

values.put("hasAlarm", 1);

Uri event = cr.insert(EVENTS_URI, values);

// reminder insert

Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(this) + "reminders");

values = new ContentValues();

values.put( "event_id", Long.parseLong(event.getLastPathSegment()));

values.put( "method", 1 );

values.put( "minutes", 10 );

cr.insert( REMINDERS_URI, values );

您还需要将此权限添加到此方法的清单中:

更新:ICS问题

上面的示例使用了未记录的Calendar API,已经为ICS发布了新的公共Calendar API,因此,为了定位新的Android版本,您应该使用CalendarContract。

关于此的更多信息可以在这篇博客文章中找到。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值