- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
Google 日历事件具有可用于将名称/值对附加到事件的扩展属性。
我们正在实现一个协作日历应用程序,该应用程序使用这些扩展属性将额外信息附加到事件中。按照 Google 的建议,我们使用 Android CalendarProvider 来读取和创建新事件。当我们创建一个新事件时,我们需要向它添加一些扩展属性,但我们刚刚意识到日历提供程序不允许编写 CalendarContract.ExtendedProperties
,如果我们尝试,我们会收到以下错误:
只有同步适配器可以使用 content://com.android.calendar/extendedproperties 写入
这些属性在 CalendarProvider 中是只读的,这似乎有点奇怪,因为它违背了它们的全部目的,即能够将一些额外的元数据附加到事件。
有人知道这个限制的解决方法吗?
最佳答案
您必须按以下步骤进行:
用于保存具有扩展属性的事件的类应该扩展 AbstractThreadedSyncAdapter ,然后实现方法 onPerfomSync(...)
public void onPerformSync(Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult) {
System.out.println("Sync......");
saveEvent();//your saving events method...
在同一个类中添加下面的方法:
static Uri asSyncAdapter(Uri uri, String account, String accountType) {
return uri.buildUpon()
.appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true")
.appendQueryParameter(Calendars.ACCOUNT_NAME, account)
.appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build();
}
创建一个扩展 Service 类的类,如下所示
public class SyncService extends Service {
private static final String TAG = "SyncService";
private static final Object sSyncAdapterLock = new Object();
private static EditEventHelper sSyncAdapter = null;
/**
* Thread-safe constructor, creates static {@link SyncAdapter} instance.
*/
@Override
public void onCreate() {
super.onCreate();
Log.i(TAG, "Service created");
synchronized (sSyncAdapterLock) {
if (sSyncAdapter == null) {
sSyncAdapter = new EditEventHelper(getApplicationContext());
}
}
}
@Override
/**
* Logging-only destructor.
*/
public void onDestroy() {
super.onDestroy();
Log.i(TAG, "Service destroyed");
}
/**
* Return Binder handle for IPC communication with {@link SyncAdapter}.
*
* <p>New sync requests will be sent directly to the SyncAdapter using this channel.
*
* @param intent Calling intent
* @return Binder handle for {@link SyncAdapter}
*/
@Override
public IBinder onBind(Intent intent) {
return sSyncAdapter.getSyncAdapterBinder();
}
在 res 路径中创建一个 xml 文件 syncadpater.xml,内容为:
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="com.android.calendar"
android:accountType="com.android.google"
android:userVisible="true"
android:supportsUploading="false"
android:allowParallelSyncs="false"
android:isAlwaysSyncable="false"
/>
用于向您的事件添加扩展属性的代码将是:
ContentValues customerContentValues_1 = new ContentValues();
customerContentValues_1.put(ExtendedProperties.EVENT_ID, model.mId);
customerContentValues_1.put(ExtendedProperties.NAME, "name");
customerContentValues_1.put(ExtendedProperties.VALUE, value);
activity.getContentResolver().insert(asSyncAdapter(ExtendedProperties.CONTENT_URI, mOwnerAccount, ACCOUNT_TYPE), customerContentValues_1);
在 AndroidManifest.xml 文件中添加这些权限:
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<!-- Required to enable our SyncAdapter after it's created. -->
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<!-- Required because we're manually creating a new account. -->
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
然后将您创建的服务声明到与 syncadapter.xml 文件关联的 list 文件中:
<service
android:name="com.android.calendar.iselection.event.SyncService"
android:exported="true" >
<!--
This intent filter is required. It allows the system to launch our sync service
as needed.
-->
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<!-- This points to a required XML file which describes our SyncAdapter. -->
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter" />
</service>
祝你好运!
关于android - 为什么 CalendarProvider 不允许写 ExtendedProperties?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27293675/
总的来说,我对 EWS 和 Exchange 很陌生,所以不确定什么是最好的方法。 背景 我正在尝试设置有关房间的配置信息。我希望 EWS API 为我提供了一个 Room 对象,我可以在该对象上添加
C# DataTable 有一个 PropertyCollection ExtendedProperties。该表中的 DataColumn 也有一个 ExtendedProperties 为什么 D
Google 日历事件具有可用于将名称/值对附加到事件的扩展属性。 我们正在实现一个协作日历应用程序,该应用程序使用这些扩展属性将额外信息附加到事件中。按照 Google 的建议,我们使用 Andro
我们正在从 Remoting 迁移到 WCF 一个非常大的应用程序,它大量使用数据集。我们使用数据集表的扩展属性来存储包含我们在客户端需要的特殊信息的对象图。 在我们的 Remoting 实现中,我们
我有一个Exchange Server,其中包含带有自定义字段的项目(例如,具有自定义ExtendedProperty值的“联系人”和“事件”)。我正在寻找一种使用Exchange Web服务(EWS
我正在使用 SyncAdapter 在 Android 应用日历上存储额外数据,例如 ExtendedProperties,在本地存储 ExtendedProperties 时效果很好,我的日历应用正
我正在尝试为我的 Activity 创建 ExtendedProperties 并收到以下错误: 02-06 09:43:04.484: E/AndroidRuntime(9530): FATAL E
我想将 Tiles 3 与 Strut 2 一起使用,所以我正在使用 struts2-tiles3-plugin。我在 web.xml 中定义了监听器,在 struts.xml 中定义了结果类型。当我
我是一名优秀的程序员,十分优秀!