Retrieving and parsing iCal data over HTTP on Android
I am making an application that asks the user for userid, appends the userid to a static HTTP link to retrieve the user's daily schedule info file that has a .ical (calendar) extension.
I need to read the data from file, format in new UI and representing some useful data on an Android device.
My query is can 开发者_C百科I access a static HTTP link behind the scenes? And when I use the same link on desktop browser, it asks user to save the file — how can I do this on a mobile? Do I need to read the data and save it somewhere or I can save the .ical file and read from it?
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:
- Get the user's ID entered in the UI
String userId = ((EditText) findById(R.id.user_id)).getText.toString();
- 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";
- Retrieve the calendar file over HTTP
- Save the file locally
- Android download binary file problems
(thanks to Pentium10)
- Android download binary file problems
- 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. :)
精彩评论