I have created a gradient drawable in the drawable folder. It is a shape in an xml file.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<gradient
android:angle="45"
android:centerColor="@color/centerColor"
android:endColor="@color/endColor"
android:startColor="@color/startColor" />
</shape>
</item>
</selector>
I am trying to set the gradient as the wallpaper for the device using the app when a certain button is clicked. Is this even possible?
Thanks in advance. :)
Java Code:
public void onClick(View v) {
// WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
InputStream is = getResources().openRawResource(R.raw.gradient);
Bitmap b = BitmapFactory.decodeStream(is);
try {
// myWallpaperManager.setBitmap(+ R.drawable.gradient);
getApplicationContext().setWallpaper(b);
Toast.makeText(getApplicationContext(),"Wallpaper updated", Toast.LENGTH_SHORT ).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}