Android download image as widget

All your problems with Audio, Video and Images.

Android download image as widget

Postby petnagy » Sun Oct 03, 2010 9:39 pm

Hi Everybody,

I have a problem, I wrote an application which will download an image from URL periodically and show it in a widget:

Code: Select all
public class WidgetImage extends AppWidgetProvider{
    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
        Timer timer = new Timer();
        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);
        }
    }
}


and couple of time download success the image but after that I can see FAILED BINDER TRANSACTION in the log, and I can not understand why ? Is there any limit ? Because if I download a small file than I do not get this error...
petnagy
Freshman
Freshman
 
Posts: 2
Joined: Sun Oct 03, 2010 9:08 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 23 guests