无法通过代码更新手机日历上的活动

atr*_*des 6 android android-calendar

我正在尝试从我的代码更新手机上的日历事件,但context.getContentResolver().update保持返回0,当然,当我在日历应用程序中查看时,没有对事件进行任何更改.

我正在使用context.getContentResolver().查询获取事件ID,开始时间等,并且我得到了像431,4,233等的唯一数字,所以我假设我正在使用的事件ID是真实.

我知道这样做的官方方法是通过谷歌的服务器,而不是使用update(),但对于我的实现,这样做是没有意义的(甚至一般情况下,但我离题了).

我做错了什么,或者我试图做一些Android根本不允许的事情?

Uri updateEventUri = ContentUris.withAppendedId(Uri.parse("content://com.android.calendar/events"), id);

ContentValues cv = new ContentValues();
begin.set(Calendar.HOUR_OF_DAY, arg0.getCurrentHour()); //begin is a java.util.Calendar object
begin.set(Calendar.MINUTE, arg0.getCurrentMinute());
//cv.put("_id", id);
//cv.put("title", "yeahyeahyeah!");
cv.put("dtstart", begin.getTimeInMillis());
int updatedrowcount = context.getContentResolver().update(updateEventUri, cv, null, null);
System.out.println("updated "+updatedrowcount+" rows with id "+id);
Run Code Online (Sandbox Code Playgroud)

相关问题已在此处发布,未回复/sf/ask/394544531/

如果我能澄清任何事情,请告诉我.我真的很感激你们和玩偶可以提供的任何输入!

nge*_*esh 3

我尝试了很多,最终得到了解决方案(虽然不可靠)..但工作正常..

public static boolean updateCalendar(Context context,String cal_Id,String eventId)
    {
    try{

        Uri CALENDAR_URI = Uri.parse(CAL_URI+"events");
        Cursor c = context.getContentResolver().query(CALENDAR_URI, null, null, null, null);
        String[] s = c.getColumnNames();

        if (c.moveToFirst())
        {
                while (c.moveToNext())
            {

                String _id = c.getString(c.getColumnIndex("_id"));
                String CalId = c.getString(c.getColumnIndex("calendar_id"));            
                if ((_id==null) && (CalId == null))
                {
                                 return false;
                }
                else
                {
                    if (_id.equals(eventId) && CalId.equals(cal_Id))
                                 {
                        Uri uri = ContentUris.withAppendedId(CALENDAR_URI, Integer.parseInt(_id));
                        context.getContentResolver().update(uri, null, null, null);// need to give your data here
                        return true;
                    }
                }
            }
        }


    }
    finally
    {
        return true;
    }
    }
Run Code Online (Sandbox Code Playgroud)

最后我不确定它是否适用于所有设备。