Is there a way to access the calendar's entries without using gdata-java-client?

后端 未结 7 698
星月不相逢
星月不相逢 2020-12-08 18:05

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

7条回答
  •  Happy的楠姐
    2020-12-08 18:24

    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).

    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);
    

    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.

提交回复
热议问题