I'm building a wallpaper application. I have a button which sets the wallpaper. What I would like to do is to check if the wallpaper is downloaded, if yes set the wallpaper - if not, download and set the wallpaper.
I check if a file with an ID (e.g. 26748.jpg
) exists, if yes I successfully set the wallpaper, if it doesn't exist, I download it - but I'm unable to set it.
I'm have a BroadcastReceiver set up:
<receiver android:name=".SinglePhotoActivity$CheckDownloadComplete">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</receiver>
which displays a simple saved message:
public static class CheckDownloadComplete extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Saved!", Toast.LENGTH_SHORT).show();
}
}
The problem is that I have two types of setting the wallpaper: one if the wallpaper is already downloaded, and one if it isn't. I've done a little research and found out that broadcast receivers of this type cannot really contain any intent extras. The only thing I could do is set a description on my DownloadManager's request and then check the description in onReceive
.
So, if the image is already downloaded, I'd like to display a simple Toast. If not, then download it and after, in OnReceive after the download has completed run my setWallpaper code.
Is there any more proficient way of doing this?