android 打开日历设定行程活动
来源:互联网 发布:java im系统 编辑:程序博客网 时间:2024/05/18 10:28
Calendar beginTime = Calendar.getInstance();beginTime.set(2012, 0, 19, 7, 30);Calendar endTime = Calendar.getInstance();endTime.set(2012, 0, 19, 8, 30);Intent intent = new Intent(Intent.ACTION_INSERT) .setData(Events.CONTENT_URI) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis()) .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis()) .putExtra(Events.TITLE, "Yoga") .putExtra(Events.DESCRIPTION, "Group class") .putExtra(Events.EVENT_LOCATION, "The gym") .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY) .putExtra(Intent.EXTRA_EMAIL, "rowan@example.com,trevor@example.com");startActivity(intent);
private static final String CALENDAR_EVENTS_URI = "content://com.android.calendar/events"; private static final String CALANDER_URL = "content://com.android.calendar/calendars";
public static int insertCalendar(Context context, String title, String desc, long startMillis, long endMillis) { final int FAIL_CODE = -1; String calendarId; Cursor userCursor = context.getContentResolver().query(Uri.parse(CALANDER_URL), null, null, null, null); if (userCursor != null && userCursor.getCount() > 0) { userCursor.moveToLast(); calendarId = userCursor.getString(userCursor.getColumnIndex("_id")); userCursor.close(); } else { showShortToast("没有账户,添加日历行程失败"); return FAIL_CODE; } ContentValues values = new ContentValues(); values.put(Events.DTSTART, startMillis); values.put(Events.DTEND, endMillis); values.put(Events.TITLE, title); values.put(Events.DESCRIPTION, desc); values.put(Events.CALENDAR_ID, calendarId); values.put(Events.EVENT_TIMEZONE, "Asia/Shanghai"); Uri uri = context.getContentResolver().insert(Uri.parse(CALENDAR_EVENTS_URI), values); String eventID = uri.getLastPathSegment(); Log.e("eventID", "insertCalendar : eventID = " + eventID); if (!TextUtils.isEmpty(eventID)) { return Integer.valueOf(eventID); } return FAIL_CODE; }
/*** * 根据title和desc来删除取消某个日历行程 * * @return true则取消成功 */ public static boolean cancelCalendar(Context context, String title, String desc) { if (ActivityCompat.checkSelfPermission(context, permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) { return false; } String selection = "((" + Events.TITLE + " = ?) AND (" + Events.DESCRIPTION + " = ?))"; String[] selectionArgs = new String[]{title, desc}; int rows = context.getContentResolver().delete(Uri.parse(CALENDAR_EVENTS_URI), selection, selectionArgs);// Log.e("rows", "Rows deleted: " + rows); return rows > 0; } /*** * 根据eventID来删除取消某个日历行程 * * @return true则取消成功 */ public static boolean cancelCalendar(Context context, long eventID) { if (ActivityCompat.checkSelfPermission(context, permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) { return false; } Uri deleteUri = ContentUris.withAppendedId(Uri.parse(CALENDAR_EVENTS_URI), eventID); int rows = context.getContentResolver().delete(deleteUri, null, null);// Log.e("rows", "Rows deleted: " + rows); return rows > 0; }
转自:http://www.jcodecraeer.com/a/anzhuokaifa/developer/2013/0311/1004.html
http://www.cnblogs.com/wblyuyang/p/4050377.html
http://www.voidcn.com/blog/omayyouhappy/article/p-6002608.html
http://www.cnblogs.com/wblyuyang/p/4050377.html
0 0
- android 打开日历设定行程活动
- Android日历行程
- android添加google日历活动
- android 6.0 日历新建活动错误
- java写的一个日历行程
- android 打开新活动并返回结果
- 行程
- 行程
- [置顶] Java 设定工作日日历
- 【iOS】日历行程的增删改查(完整)
- android设定自己应用为打开某程序的应用
- 关于本次聚会的活动行程和主题的讨论!
- 打开Android系统自带日历的新建提醒界面
- 如何打开系统日历
- Android日历
- android 日历
- android 日历
- Android-日历
- OSG总结
- IOS的基本控件的使用-UIViewController使用
- yum升级CURL到最新版本的方法,非常好用
- 软工作业设计阶段
- php写入txt追加
- android 打开日历设定行程活动
- 利用Hog特征和SVM分类器进行行人检测
- Java socket编程
- SQL Server中行列转换 Pivot UnPivot
- PAT(A) 1003. Emergency (25)
- VS 调试时“还没有为该文档加载任何符号”
- lua的string库与强大的模式匹配
- 动态的改变IFrame的高度
- 用Div做到单选按钮radio自定义样式功能