0

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?

misaochan
  • 890
  • 2
  • 8
  • 25
  • Maybe your app needs special permission to download data from e web? – Michael May 27 '13 at 14:03
  • Thanks for the suggestion, Michael. I have considered that, but from what I've read, enabling Internet permissions should suffice. Besides, wouldn't that give me a network exception instead of a file not found exception? – misaochan May 28 '13 at 12:22
  • When I try to view it (on my iPad) I get a "Download failed" message. – Michael May 28 '13 at 14:10
  • 1
    The exception messages says, "No content provider". Maybe you have to register whatever Content-Type the response is returning so Android knows how to handle it. Or you could try making the server set the Content-Type to something generic like "text/plain". – Michael May 28 '13 at 14:14
  • Unfortunately I don't have control over the server. How will I make my programme register the Content-Type of the response to text, please? It's a vcard file. – misaochan May 29 '13 at 02:11
  • 1
    I don't know anything about Android. Maybe there's a more "raw" way that you could download the file? Do you have access to the HttpURLConnection class in Android? – Michael May 29 '13 at 14:37
  • It seems I do, yes. Thanks for the tip, will try it out. – misaochan May 31 '13 at 13:34
  • @melange did you manage to solve this? – Luis LL Jul 16 '13 at 11:06

0 Answers0