• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Display doesn't update

durin

Lurker
Aug 16, 2010
2
0
Hi!

I'm stuck with a simple program. I have a (external) webcam and I want to grab the image there every x seconds and display it on my android. My problem is that the display doesn't update. When I put everything in one class it works perfectly. The code beneath compiles and runs without any error but there must be something I missed because the screen stays black. Any suggestion what I overred or forgot?
Thanks a lot!
Durin

Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.me.cam;

import android.app.Activity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.util.Timer;
import java.util.TimerTask;

/**
 *
 * @author and
 */
public class CammCam extends Activity {

    public static Drawable drawable;
    public static ImageView imgView;

    public int seconds = 10;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Timer timer = new Timer();
        imgView = (ImageView) findViewById(R.id.ImageView01);
        timer.schedule(new WebcamUpdate(), seconds * 1000);
    }

    public static ImageView getImgView(){
        return imgView;
    }

     public static Drawable getDrawable(){
        return drawable;
    }

}

class WebcamUpdate extends TimerTask {
    String inputUrl = "http://my-url-.com";

    public void run() {
           Drawable drawable=CammCam.getDrawable();
           ImageView imgView=CammCam.getImgView();
           Log.d(this.toString(),"Updating Cam...");
           drawable=LoadImageFromWebOperations(inputUrl);
           imgView.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) {
            System.out.println("Exc=" + e);
            return null;
        }
    }

  }
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones