4

我正在制作一个向用户询问用户 ID 的应用程序,将用户 ID 附加到静态 HTTP 链接以检索具有 .ical(日历)扩展名的用户的每日计划信息文件。

我需要从文件中读取数据,在新 UI 中格式化并在 Android 设备上表示一些有用的数据。

我的查询是我可以在后台访问静态 HTTP 链接吗?当我在桌面浏览器上使用相同的链接时,它会要求用户保存文件——我怎么能在手机上做到这一点?我是否需要读取数据并将其保存在某处,或者我可以保存 .ical 文件并从中读取?

4

1 回答 1

4

Android devices generally cannot handle iCalendar-formatted files (.ics) — there is no way to just "open" such a file and have the information displayed. You would have to write some code (or use a library such as iCal4j) to parse the information in the calendar file.

Based on your question and comments, you need to break this into a few parts:

  1. Get the user's ID entered in the UI
    • String userId = ((EditText) findById(R.id.user_id)).getText.toString();
  2. Generate the user's unique calendar URL
    • static final String CALENDAR_BASE = "http://example.com/cal/";
      String escapedUserId = URLEncoder.encode(userId, "UTF-8");
      String url = CALENDAR_BASE + escapedUserId +"/events.ics";
  3. Retrieve the calendar file over HTTP
  4. Save the file locally
  5. Display the calendar data to the user
    • Read the file from disk that you saved directly from the web
    • Parse the data with iCal4j and display in whatever UI format you like

You can search Stack Overflow or post a more particular question regarding any of the individual parts if you're unsure or need some more specific info. :)

于 2010-01-24T00:49:54.850 回答