android - 使用 Android 日历

标签 android

我正在尝试向 Android 日历 (2.2) 添加条目,但我遇到了一些错误。 我尝试了很多测试但没有成功。请问出了什么问题? 对不起我的英语。

源代码:

String calName; 
        String calId = null;
        String[] projection = new String[] { "_id", "name" };
        Uri calendars = Uri.parse("content://com.android.calendar/calendars");
        Cursor managedCursor = managedQuery(calendars, projection, "selected=1", null, null);
        ContentValues event = new ContentValues();
        DateFormat date = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");

        long time = System.currentTimeMillis();
        String timeStr = date.format(time);
        Log.d(TAG, "Value of timeStr: " + timeStr);



        if (managedCursor.moveToNext()) {
            calName = managedCursor.getString(managedCursor.getColumnIndex("name"));
            calId = managedCursor.getString(managedCursor.getColumnIndex("_id"));
            event.put("calendar_id", calId);
            event.put("title", "Event Title");
            event.put("description", "Description");
            event.put("eventLocation", "New York");
            event.put("dtstart", timeStr );
            event.put("dtend", timeStr);
            Uri eventsUri = Uri.parse("content://com.android.calendar/events");
            Uri url = getContentResolver().insert(eventsUri, event);


            }

最佳答案

首先,请针对您的错误发布 StackTrace。 第二:在尝试 managedCursor.moveToNext 之前,使用:

managedCursor.moveToFirst();

然后

while(managedCursor.moveToNext()){ };

关于android - 使用 Android 日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5613413/

相关文章:

java - 我从第一个 Activity 中获取数据。在第二个 Activity 中,我尝试输入一个值,以便 y=beta0 +beta1*x。但是当我输入x时,结果y是0

java - 如何从字符串数组列表中随机选择

android - 在android中从mysql数据库搜索多个数据时出现问题

java - Firebase getUid() 函数仅返回 NULL

android - RxBinding出错后如何重新绑定(bind)View?

android - 将图像放在坐标 Android

android - 适用于 Android 的 Facebook SDK - 示例应用程序无法运行

android - 滑动时 ViewPager 更新 fragment

android - Cordova 应用程序无法使用人行横道插件安装 64 位 APK

android - 停止在 MPAndroidChart 中突出显示条形颜色?