android 修改本地日程后 修改后的数据查看 demo
时间: 2023-10-06 19:04:30 浏览: 74
Android应用源码之Android系统日历日程操作.zip_android_android 日程demo
5星 · 资源好评率100%
您可以使用以下代码来获取修改后的日程数据:
```java
// 获取 ContentResolver
ContentResolver cr = getContentResolver();
// 定义查询条件
Uri uri = CalendarContract.Events.CONTENT_URI;
String[] projection = new String[]{
CalendarContract.Events._ID,
CalendarContract.Events.TITLE,
CalendarContract.Events.DESCRIPTION,
CalendarContract.Events.DTSTART,
CalendarContract.Events.DTEND
};
String selection = CalendarContract.Events.TITLE + " = ?";
String[] selectionArgs = new String[]{"My Event"};
// 查询数据
Cursor cursor = cr.query(uri, projection, selection, selectionArgs, null);
// 遍历结果集合
while (cursor.moveToNext()) {
String eventId = cursor.getString(cursor.getColumnIndex(CalendarContract.Events._ID));
String title = cursor.getString(cursor.getColumnIndex(CalendarContract.Events.TITLE));
String description = cursor.getString(cursor.getColumnIndex(CalendarContract.Events.DESCRIPTION));
long startTime = cursor.getLong(cursor.getColumnIndex(CalendarContract.Events.DTSTART));
long endTime = cursor.getLong(cursor.getColumnIndex(CalendarContract.Events.DTEND));
Log.d("TAG", "Event Id: " + eventId);
Log.d("TAG", "Title: " + title);
Log.d("TAG", "Description: " + description);
Log.d("TAG", "Start Time: " + new Date(startTime));
Log.d("TAG", "End Time: " + new Date(endTime));
}
// 关闭游标
cursor.close();
```
其中,`CalendarContract.Events.TITLE` 表示查询条件,你可以根据自己的情况修改它。注意,查询数据需要获取相应的权限。
阅读全文