有没有一种方法来访问日历的条目,而无需使用gdata的Java的客户端? [英] Is there a way to access the calendar's entries without using gdata-java-client?

查看:98
本文介绍了有没有一种方法来访问日历的条目,而无需使用gdata的Java的客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从手机离线获得日历的条目?它似乎是唯一的方法是使用 gdata的Java的客户端

Is it possible to get the calendar's entries from the phone offline? It seem the only way is to use gdata-java-client.

推荐答案

这些回答都不错,但他们都涉及到硬编码日历URI (我已经可见在不同的Andr​​oid设备三种不同的化身)。

These answers are good, but they all involve hard-coding the Calendar URI (which I've seen in three different incarnations across different Android devices).

一个更好的方式来获取 URI (其中硬codeS一类的名称和场代替)会是这样的:

A better way to get that URI (which hard-codes the name of a class and a field instead) would be something like this:

Class<?> calendarProviderClass = Class.forName("android.provider.Calendar");
Field uriField = calendarProviderClass.getField("CONTENT_URI");
Uri calendarUri = (Uri) uriField.get(null);

这是不完美的(这将打破,如果他们曾经删除 android.provider.Calendar 类或 CONTENT_URI 字段),但它的工作原理上比任何单一的URI硬code更多的平台。

This isn't perfect (it will break if they ever remove the android.provider.Calendar class or the CONTENT_URI field) but it works on more platforms than any single URI hard-code.

请注意,这些反射方法将抛出例外这将需要被捕获或者再抛出调用方法。

Note that these reflection methods will throw exceptions which will need to be caught or re-thrown by the calling method.

这篇关于有没有一种方法来访问日历的条目,而无需使用gdata的Java的客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆