如何将私人数据附加到 Android 日历事件
我们如何将一些额外的数据附加到日历事件,如文件、照片、简单的字符串等,..
我使用了扩展属性,并且能够通过扩展属性插入一些额外的数据
Uri extendedProperties=Uri.parse("content://com.android.calendar/extendedproperties");
ContentValues extendedValues=new ContentValues();
extendedValues.put("event_id", id);
extendedValues.put("name",key);
extendedValues.put("value",value);
getApplicationContext().getContentResolver().insert(extendedProperties, extendedValues);
,然后能够检索该数据,如下所示
Uri extentdedProperties=Uri.parse("content://com.android.calendar/extendedproperties");
CursorextendedPropertires Cursor=getContentResolver().query(extentdedProperties,null,"event_id = "+Id +",null,null);
它可以很好地使用android 2.2 ...如果在 android 4.0(冰淇淋三明治)中测试,则相同的代码。它抛出一个错误,指出只有同步适配器可以访问 content://com.android.calendar/extendedproperties。
所以我将查询执行为“callerissyncadapter”。现在我可以插入扩展属性。但是,一旦事件同步到服务器,扩展属性就会被服务器删除。
即使这些扩展属性也不受日历提供程序(谷歌除外)的完全支持,除了
扩展属性之外,还有什么方法可以将一些额外的数据附加到日历事件,或者我们可以以更好的方式利用此扩展属性。
How can we attach some extra data to a calendar event like files,photos,a simple string etc,..
i used extended properties and able to insert some extra data via extended properties
Uri extendedProperties=Uri.parse("content://com.android.calendar/extendedproperties");
ContentValues extendedValues=new ContentValues();
extendedValues.put("event_id", id);
extendedValues.put("name",key);
extendedValues.put("value",value);
getApplicationContext().getContentResolver().insert(extendedProperties, extendedValues);
and later able to retrieve that data like below
Uri extentdedProperties=Uri.parse("content://com.android.calendar/extendedproperties");
CursorextendedPropertires Cursor=getContentResolver().query(extentdedProperties,null,"event_id = "+Id +",null,null);
It works fine with android 2.2 ... Same code if tested in android 4.0 (ice cream sandwich). It is throwing a error saying that only sync adapters can access content://com.android.calendar/extendedproperties.
So i exectued the query as "callerissyncadapter". Now i am able to insert extended properties. But once event is synced to server , extended properties are being deleted by the server.
Even these extended properties are not fully supported by calendar providers (other than google)
Is there any way to attach some extra data to calendar event other than extendedproperties or can we make use of this extended properties in a more better way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您确实是同步适配器,否则请勿使用 callerissyncadapter。将其设置为 true 将导致设备上的内容观察者不会收到该提供程序中内容更改的通知,并且您的更改不会保留到服务器。
你为什么要尝试这样做?您是否正在尝试将应用程序的一些数据与日历事件相关联?
如果是这样,为什么不使用您的应用程序创建您自己的私有数据存储(或内容提供程序),并根据日历内容提供程序中的事件键对您的额外属性进行索引?这样,您的应用程序数据和公共联系人内容提供商数据之间就建立了关联。
Do not use callerissyncadapter unless you are really the sync adapter. Setting this to true will cause content observers on the device to not be notified of changes to content in that provider and for your changes to not be persisted to the server.
Why are you trying to do this? Are you trying to associate some data for your app with a calendar event?
If so, why not create your own, private data store (or content provider) with your application and index your extra properties by the key of the events in the calendar content provider? This way, you have an association between your app's data and the public contacts content provider data.