Islam Hassan
Islam Hassan

Reputation: 1736

Android: openInputStream with URL throws FileNotFoundException

I'm trying to run the following code

    Uri uri = Uri.parse("URL of a photo");

    ContentResolver cr = getContentResolver();

    try {
        InputStream fis = cr.openInputStream(uri);
        // Do some stuff here ..
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

But this throws a FileNotFoundException, and I'm sure the URL is correct. Is there another way to open input stream of a URL?

EDIT: LogCat output

11-06 22:05:37.939: W/System.err(20057): java.io.FileNotFoundException: No content provider: http://www.vnvlvokc.com/ow_userfiles/plugins/shoppro/images/product_1.jpg
11-06 22:05:37.939: W/System.err(20057):    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:481)
11-06 22:05:37.939: W/System.err(20057):    at android.content.ContentResolver.openInputStream(ContentResolver.java:319)
11-06 22:05:37.939: W/System.err(20057):    at com.example.myfacebook.Act1.post_photo(Act1.java:68)
11-06 22:05:37.939: W/System.err(20057):    at com.example.myfacebook.Act1.onActivityResult(Act1.java:58)
11-06 22:05:37.939: W/System.err(20057):    at android.app.Activity.dispatchActivityResult(Activity.java:3908)
11-06 22:05:37.939: W/System.err(20057):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2694)
11-06 22:05:37.939: W/System.err(20057):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:2740)
11-06 22:05:37.939: W/System.err(20057):    at android.app.ActivityThread.access$2000(ActivityThread.java:121)
11-06 22:05:37.939: W/System.err(20057):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:991)
11-06 22:05:37.939: W/System.err(20057):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 22:05:37.939: W/System.err(20057):    at android.os.Looper.loop(Looper.java:130)
11-06 22:05:37.939: W/System.err(20057):    at android.app.ActivityThread.main(ActivityThread.java:3892)
11-06 22:05:37.949: W/System.err(20057):    at java.lang.reflect.Method.invokeNative(Native Method)
11-06 22:05:37.949: W/System.err(20057):    at java.lang.reflect.Method.invoke(Method.java:507)
11-06 22:05:37.949: W/System.err(20057):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
11-06 22:05:37.949: W/System.err(20057):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:642)
11-06 22:05:37.949: W/System.err(20057):    at dalvik.system.NativeStart.main(Native Method)

Upvotes: 3

Views: 5567

Answers (1)

Snicolas
Snicolas

Reputation: 38168

If you want to download the content of the picture to the phone, then you should not use an intent resolver but a HttpUrlConnection and copy its content to a file.

There are several ways to do that, few are corrects. If that's what you want to do tell me, I will give you some hints.

What you are doing with the content resolver is trying to get a ContentProvider from an app or from the system that could give you the content of this url.. it's really a bit awkward.

Upvotes: 4

Related Questions