Android download image as widget

All your problems with Audio, Video and Images.

Android download image as widget

Postby petnagy » Mon Oct 04, 2010 7:19 pm

Hi Everybody,

I am new here, but I have a problem, I have written a program which periodically load an image from the net (bitmap, and from URL) but after a couple success download it will send some FAILED BIND TRANSACTION in the logcat.
Could someone help me, what could be wrong ?

Code: Select all
public class WidgetImage extends AppWidgetProvider{
    Timer timer = new Timer();
   
    @Override
    public void onDeleted(Context context, int[] appWidgetIds) {
        timer.purge();
    }
   
    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
       
        timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 10,10000);
    }
   
    @Override
    public void onReceive(Context context, Intent intent) {
        // v1.5 fix that doesn't call onDelete Action
        final String action = intent.getAction();
        if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
            final int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
           
            if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
                this.onDeleted(context, new int[] { appWidgetId });
            }
        } else {
            super.onReceive(context, intent);
        }
    }

    private class MyTime extends TimerTask {
        RemoteViews remoteViews;
        AppWidgetManager appWidgetManager;
        ComponentName thisWidget;
        DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());

        public MyTime(Context context, AppWidgetManager appWidgetManager) {
            this.appWidgetManager = appWidgetManager;
            remoteViews = new RemoteViews(context.getPackageName(),R.layout.main);
            thisWidget = new ComponentName(context, WidgetImage.class);
        }

        @Override
        public void run() {
            remoteViews.setTextViewText(R.id.widget_textview, "Time = "+ format.format(new Date()));
           
            try {
                /* Open a new URL and get the InputStream to load data from it. */
                URL aURL = new URL("http://upload.wikimedia.org/wikipedia/commons/thumb/6/64/Collage_of_Six_Cats-02.jpg/250px-Collage_of_Six_Cats-02.jpg");
                URLConnection conn = aURL.openConnection();
                conn.connect();
                InputStream is = conn.getInputStream();
                /* Buffered is always good for a performance plus. */
                BufferedInputStream bis = new BufferedInputStream(is);
                /* Decode url-data to a bitmap. */
                Bitmap bm = BitmapFactory.decodeStream(bis);
                bis.close();
                is.close();
                /* Apply the Bitmap to the ImageView that will be returned. */
                remoteViews.setImageViewBitmap(R.id.webview, bm);
            } catch (IOException e) {
                //i.setImageResource(R.drawable.error);
                Log.e("DEBUGTAG", "Remtoe Image Exception", e);
            }
           
            appWidgetManager.updateAppWidget(thisWidget, remoteViews);
        }
    }
}
petnagy
Freshman
Freshman
 
Posts: 2
Joined: Sun Oct 03, 2010 9:08 pm

Top

Re: Android download image as widget

Postby kuwamebrown » Fri Dec 24, 2010 7:38 am

Can someone help me out!, I've been strugling for a days trying to figure out how to make a button which able the user to download a file such as mp3 or text, I tried to search in everywhere but failed to succeed, some of the code that I used just let me open a new browser, I want the user to open to be able to download the file inside of my own app. PLease if you have an easy way to do it would you be kind to show me! I would I appreciate your kindness thanks.
kuwamebrown
Junior Developer
Junior Developer
 
Posts: 11
Joined: Fri Dec 24, 2010 7:28 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 12 guests