1

I've searched and tried a couple different methods. I am coming up short on both. This is my current method:

package com.dop.mobilevforum;

import java.io.InputStream;
import java.net.URL;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.VideoView;

public class Vforum extends Activity
{
    private String imgPath = "http://mysite.com/mv/vfdemo1/slides/slide1.jpg";

    private ImageView slideHolder;

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vforum);

        slideHolder = (ImageView) findViewById(R.id.slideHolder);

        Drawable drawable = LoadImageFromWebOperations(imgPath);
        slideHolder.setImageDrawable(drawable);
    }

    private Drawable LoadImageFromWebOperations(String url)
    {
        try
        {
            InputStream is = (InputStream) new URL(url).getContent();
            Drawable d = Drawable.createFromStream(is, "src name");
            return d;
        } 
        catch (Exception e)
        {
            Log.w("LoadImageFromWebOperations",e.toString());
            return null;
        }
    }
}

the LoadImageFromWebOperations method is returning a bitmap, so I know that part is working. It is the slideHolder.setImageDrawable(drawable); that I think it failing. This is my XML:

<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mobile_vforum_bg">
    <ImageView 
        android:id="@+id/slideHolder"
        android:layout_width="320px" 
        android:layout_height="240px">
    </ImageView>
</FrameLayout>

any ideas? I just get a black screen, no errors.

2
  • A couple of OS projects I've seen just used a WebView to show images. Commented May 16, 2011 at 20:38
  • using web view was so much easier! Commented May 16, 2011 at 22:07

2 Answers 2

2

Your best bet is using a WebView, but if you really want to do it this way don't use setImageDrawable. You should use setImageBitmap. If your LoadImageFromWebOperations returns a Bitmap then you shouldn't change anything, but the function you are using and it should work smoothly.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, WebView is the way to go. That was too easy. Also, when I said bitmap, I meant that generically like an image. I should have been more clear. It indeed was returning a Drawable.
0

Your code work, my dear friend your url don't work http://mysite.com/mv/vfdemo1/slides/slide1.jpg.

You can use this it works 100%, but your code also works

URL url = new URL("http://variable3.com/files/images/email-sig.jpg");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
slideHolder.setImageBitmap(bmp);

1 Comment

My URL does work. I changed it because it is information that I do not want people to see. Regardless, I tried your code and I couldn't get it to work. I ended up using a WebView

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.