使用Android日历

使用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/cale

我正在尝试向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()){ };

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

managedCursor.moveToFirst();
然后

while(managedCursor.moveToNext()){ };

我无法发布StackTrace,因为我的AVD没有任何日历,我正在HTC Desire上测试它(如果有任何方法可以将android日历安装到AVD或从我的手机调试项目,请告诉我…)和managedCursor.moveToFirst();然后是while(managedCursor.moveToNext()){};我已经试过了,但是没有成功,AVD没有日历。您可以使用Logcat在手机上调试应用程序,在谷歌上搜索Logcat和Android。我无法发布StackTrace,因为我的AVD没有任何日历,我正在HTC Desire上测试它(如果有任何方法可以将Android日历安装到AVD或从我的手机上调试项目,请告诉我…)和managedCursor.moveToFirst();然后是while(managedCursor.moveToNext()){};我已经试过了,但是没有成功,AVD没有日历。你可以用Logcat在手机上调试应用程序,在谷歌上搜索Logcat和Android。