I'm making an image-downloading app that sets the image as the device wallpaper. For this I used the class:
ImageDownloader.java
This class has a function which accepts a url and an ImageView. It downloads and assigns the image found at the url to the ImageView using an AsyncTask class defined within.
I managed to implement it as intended and wanted to extend its use to helping me set the devices wallpaper. This turned out to be pretty complicated but I managed with the following code in my MainActivity.java:
public class MainActivity extends Activity {
private final ImageDownloader mDownload = new ImageDownloader();
public static Bitmap bima=null;
public static WallpaperManager wm;
in onCreate:
wm = WallpaperManager.getInstance(getApplicationContext());
mDownload.download(url,imageView);
method defined in the MainActivity.Java:
public static void setbima(Bitmap bimu) {
try {wm.setBitmap(bimu);} catch (Exception e) {}
}
Then I used my function in the ImageDownloader class's AsyncTask's onPostExecute like this:
MainActivity.setbima(bitmap);
Making use of the bitmap that was being passed to there by the AsyncTask class.
With the WallpaperManager object I wanted to make use of that bitmap, because its function .setBitmap() accepts bitmaps and puts the system wallpaper to that bitmap.
I am just wondering if my way of achieving this is optimal or is there a simpler way to have achieved this? It seems a very far-fetched way of doing this and I wouldn't be surprised if it is as I am a beginner programmer.