rwrwr
Lurker
I am trying to save the screenshot of a particular layout in which I am being successful, the problem is how I can set that screenshot taken as wallpaper of android. I tried using wallpaper.setResource() but it asks for int type, so is it there any way of making the screenshot taken as wallpaper of Android or even without saving the screenshot, how can I make a particular layouts screenshot as wallpaper of android?
The code I used for taking and saving screenshot is:
The code I used for taking and saving screenshot is:
Code:
try {
// image naming and path to include sd card appending name you choose for file
//actionBar.hide();
Date currentTime = Calendar.getInstance().getTime();
String mPath = Environment.getExternalStorageDirectory().toString() + "/useless/" +currentTime + ".jpg";
fabSpeedDial.setVisibility(View.INVISIBLE);
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
v1=findViewById(R.id.l1);
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
fabSpeedDial.setVisibility(View.VISIBLE);
//actionBar.show();
makeText(MainActivity.this,"Saved Successfully", Toast.LENGTH_SHORT).show();
return true;
} catch (Throwable e) {
e.printStackTrace();
makeText(MainActivity.this,"Error Occured", Toast.LENGTH_SHORT).show();return true;
}
}
Last edited by a moderator: