java - 尝试为 android-calendar 实现 ExtendedProperties 时出现 IllegalArgumentException

标签 java eclipse android-calendar

我正在尝试为我的 Activity 创建 ExtendedProperties 并收到以下错误:

02-06 09:43:04.484: E/AndroidRuntime(9530): FATAL EXCEPTION: IntentService[AsyncQueryServiceHelper]
02-06 09:43:04.484: E/AndroidRuntime(9530): java.lang.IllegalArgumentException: Only sync adapters may write using content://com.android.calendar/extendedproperties
02-06 09:43:04.484: E/AndroidRuntime(9530):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
02-06 09:43:04.484: E/AndroidRuntime(9530):     at android.database.DatabaseUtils.readExceptionWithOperationApplicationExceptionFromParcel(DatabaseUtils.java:160)
02-06 09:43:04.484: E/AndroidRuntime(9530):     at android.content.ContentProviderProxy.applyBatch(ContentProviderNative.java:484)
02-06 09:43:04.484: E/AndroidRuntime(9530):     at android.content.ContentProviderClient.applyBatch(ContentProviderClient.java:227)
02-06 09:43:04.484: E/AndroidRuntime(9530):     at android.content.ContentResolver.applyBatch(ContentResolver.java:954)
02-06 09:43:04.484: E/AndroidRuntime(9530):     at com.android.calendar.iselection.AsyncQueryServiceHelper.onHandleIntent(AsyncQueryServiceHelper.java:327)
02-06 09:43:04.484: E/AndroidRuntime(9530):     at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
02-06 09:43:04.484: E/AndroidRuntime(9530):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 09:43:04.484: E/AndroidRuntime(9530):     at android.os.Looper.loop(Looper.java:176)
02-06 09:43:04.484: E/AndroidRuntime(9530):     at android.os.HandlerThread.run(HandlerThread.java:61)

我的代码如下:

ContentValues customerContentValues = new ContentValues();
Uri uriExtendedProperties = Uri.parse("content://com.android.calendar/extendedproperties");
customerContentValues.put(Events._ID,model.mId);
customerContentValues.put("ClientIdname", model.mCustomerName);
customerContentValues.put("RdvType", model.mEventType);
customerContentValues.put("RdvEmplacement", model.mEmplacement);
customerContentValues.put("RdvAdresse", model.mAddresse);
ops.add(ContentProviderOperation.newInsert(uriExtendedProperties).withValues(customerContentValues).build());

有什么我错过的吗?需要一些插入..提前致谢

有没有人可以告诉我更多关于同步适配器的信息,因为我真的很困惑......任何建议都会受到欢迎。

最佳答案

ExtendedProperties 与普通的 EvnetsAttendees 表略有不同。

为了写入它,您需要修改您正在使用的 uri 并添加“caller_is_syncadapter”、“account_name' 和 'account_type' 参数。

这是一个例子:

Uri extendedPropUri = ExtendedProperties.CONTENT_URI;
    extendedPropUri = extendedPropUri.buildUpon()
            .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER,"true")
            .appendQueryParameter(Calendars.ACCOUNT_NAME, this.accountName)
            .appendQueryParameter(Calendars.ACCOUNT_TYPE, this.accountType).build();

然后插入看起来像:

ContentValues extraDataValues = new ContentValues();
extraDataValues.put(ExtendedProperties.EVENT_ID, eventId);
extraDataValues.put(ExtendedProperties.NAME, key);
extraDataValues.put(ExtendedProperties.VALUE, value);

context.getContentResolver().insert(extendedPropUri, extraDataValues);

关于java - 尝试为 android-calendar 实现 ExtendedProperties 时出现 IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28362241/

相关文章:

java - 绘画程序的撤消方法

java - 向 JButton 添加操作事件

Java代码获取Maven依赖图

java - JDatePicker jar 找不到本地 en_GB?

android - 如何阅读谷歌日历中的提醒

java - 使用父类(super class)的 JAXB 注释子类 XMLRootElement 名称值

java - 对象属性绑定(bind)库

Android 日历 View 。连续显示月份

java - 尝试让简笔画在屏幕上移动,收到错误消息

android - 获取当前日期作为字符串警告已弃用 toGmtString() 问题