Jeet
Jeet

Reputation: 115

Changing Background of an app

Here is sample code:

        WallpaperManager wallpaperManager1 = WallpaperManager
                .getInstance(getApplicationContext()); 

        final Drawable wallpaperDrawable1 = wallpaperManager1.getDrawable();
        getWindow().setBackgroundDrawable(wallpaperDrawable1);

        if (wallpaperDrawable1==null)
        {                       
            Resources res = getResources();
            Drawable drawable1=res.getDrawable(R.drawable.bg1);
            getWindow().setBackgroundDrawable(drawable1);

        }

I wanted to get the system background in my app, If its not there or if user removes it, then I wanted to set a default image from my app to set as app background. Hope Its all clear....

Upvotes: 2

Views: 441

Answers (1)

ariefbayu
ariefbayu

Reputation: 21979

To see if current system has wallpaper, you use peekDrawable():

final Drawable wallpaperDrawable1 = wallpaperManager1.peekDrawable();

Also, you missed else:

if (wallpaperDrawable1==null)
{                       
    Resources res = getResources();
    Drawable drawable1=res.getDrawable(R.drawable.bg1);
    getWindow().setBackgroundDrawable(drawable1);

}
else
{
    getWindow().setBackgroundDrawable(wallpaperDrawable1);
}

Upvotes: 2

Related Questions