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{
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 10,10000);
    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,
            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);

        public void run() {
            remoteViews.setTextViewText(, "Time = "+ format.format(new Date()));
            try {
                /* Open a new URL and get the InputStream to load data from it. */
                URL aURL = new URL("");
                URLConnection conn = aURL.openConnection();
                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);
                /* Apply the Bitmap to the ImageView that will be returned. */
                remoteViews.setImageViewBitmap(, bm);
            } catch (IOException e) {
                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...
Posts: 2
Joined: Sun Oct 03, 2010 9:08 pm


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 26 guests