Android Open Source - XKCDWidget Get Image Task






From Project

Back to project page XKCDWidget.

License

The source code is released under:

MIT License

If you think the Android project XKCDWidget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * (c) 2011 Anthony Sandrin/*from   w ww  .j a  va  2s.  c o  m*/
 * This code is licensed under MIT license (see LICENSE.txt for details)
 */

package me.sandrin.xkcdwidget;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

public class GetImageTask extends AsyncTask<String, Void, Bitmap> {
    @Override
    protected Bitmap doInBackground(String... params) {
        String imageUrl = params[0];
        Bitmap image = null;
        try {
            image = BitmapFactory.decodeStream((InputStream) new URL(imageUrl).getContent());
        } catch (IOException e) {
            Log.e("XKCD", "Unable to get XKCD image.", e);
        }
        return image;
    }
}




Java Source Code List

me.sandrin.xkcdwidget.GetImageTask.java
me.sandrin.xkcdwidget.GetJsonTask.java
me.sandrin.xkcdwidget.XKCDAppWidgetProvider.java