有没有一种方法来访问日历的条目,而无需使用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-cl...

是否有可能从手机离线获得日历的条目?它似乎是唯一的方法是使用 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.

阅读全文

相关推荐

最新文章