1. Are you ready for the Galaxy S20? Here is everything we know so far!

Display doesn't update

Discussion in 'Android Development' started by durin, Aug 16, 2010.

  1. durin

    durin Lurker
    Thread Starter

    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 (Text):
    1.  
    2. /*
    3.  * To change this template, choose Tools | Templates
    4.  * and open the template in the editor.
    5.  */
    6. package org.me.cam;
    7.  
    8. import android.app.Activity;
    9. import android.os.Bundle;
    10. import android.app.Activity;
    11. import android.content.Context;
    12. import android.graphics.drawable.Drawable;
    13. import android.os.Bundle;
    14. import android.text.Editable;
    15. import android.util.Log;
    16. import android.view.View;
    17. import android.view.View.OnClickListener;
    18. import android.widget.Button;
    19. import android.widget.EditText;
    20. import android.widget.ImageView;
    21. import android.widget.TextView;
    22. import java.io.IOException;
    23. import java.io.InputStream;
    24. import java.net.*;
    25. import java.util.Timer;
    26. import java.util.TimerTask;
    27.  
    28. /**
    29.  *
    30.  * @author and
    31.  */
    32. public class CammCam extends Activity {
    33.  
    34.     public static Drawable drawable;
    35.     public static ImageView imgView;
    36.  
    37.     public int seconds = 10;
    38.  
    39.     @Override
    40.     public void onCreate(Bundle savedInstanceState) {
    41.         super.onCreate(savedInstanceState);
    42.         setContentView(R.layout.main);
    43.         Timer timer = new Timer();
    44.         imgView = (ImageView) findViewById(R.id.ImageView01);
    45.         timer.schedule(new WebcamUpdate(), seconds * 1000);
    46.     }
    47.  
    48.     public static ImageView getImgView(){
    49.         return imgView;
    50.     }
    51.  
    52.      public static Drawable getDrawable(){
    53.         return drawable;
    54.     }
    55.  
    56. }
    57.  
    58. class WebcamUpdate extends TimerTask {
    59.     String inputUrl = "http://my-url-.com";
    60.  
    61.     public void run() {
    62.            Drawable drawable=CammCam.getDrawable();
    63.            ImageView imgView=CammCam.getImgView();
    64.            Log.d(this.toString(),"Updating Cam...");
    65.            drawable=LoadImageFromWebOperations(inputUrl);
    66.            imgView.setImageDrawable(drawable);
    67.     }
    68.  
    69.  
    70.     private Drawable LoadImageFromWebOperations(String url) {
    71.         try {
    72.             InputStream is = (InputStream) new URL(url).getContent();
    73.             Drawable d = Drawable.createFromStream(is, "src name");
    74.             return d;
    75.         } catch (Exception e) {
    76.             System.out.println("Exc=" + e);
    77.             return null;
    78.         }
    79.     }
    80.  
    81.   }
    82.  
     


Loading...

Share This Page

Loading...