I have a list of IDs, each one linked to the web URL of a vCard when clicked. My goal is that when the user clicks on an ID, he will be brought to a new page displaying the vCard data. So onItemClick, parse the vCard data, then display a new view with the parsed vCard data.
I've searched for this, but I can't find anything that is able to import directly from the web and display the details in my application. All the tutorials I can find seem to have to go through the step of downloading the vCard data to the SDcard before the data can be parsed from a local file. Is there a way to do this without going through the SDcard?
My code:
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
Intent i = new Intent(Intent.ACTION_VIEW);
Uri.Builder b = Uri.parse("http://www.cs.auckland.ac.nz/our_staff/vcard.php").buildUpon();
b.appendQueryParameter("upi", items.get(pos));
Uri uri = b.build();
ContentResolver cr = activity.getContentResolver();
InputStream stream = null;
try {
stream = cr.openInputStream(uri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StringBuffer fileContent = new StringBuffer("");
int ch;
try {
while( (ch = stream.read()) != -1)
fileContent.append((char)ch);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String data = new String(fileContent);
Log.i("TAG", "data: " + data);
}
}
Gives me the exception:
05-26 11:29:09.723: W/System.err(781): java.io.FileNotFoundException: No content provider: http://www.cs.auckland.ac.nz/our_staff/vcard.php?upi=kng001
05-26 11:29:09.723: W/System.err(781): at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:710)
05-26 11:29:09.733: W/System.err(781): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:614)
05-26 11:29:09.733: W/System.err(781): at android.content.ContentResolver.openInputStream(ContentResolver.java:449)
05-26 11:29:09.733: W/System.err(781): at com.lim.json.StaffListListener.onItemClick(StaffListListener.java:53)
Oddly, the URL in the exception http://www.cs.auckland.ac.nz/our_staff/vcard.php?upi=kng001 is actually the correct URL. I have tested it and it is valid. Why still this exception?