Hello everyone I will try to be as clear as possible .... I have a method in which I get the Screen of my App, what I would really like is to be able to use my method to get Screen from other apps, or the Android desktop, The way I try to do it is before I capture the screen, I transform my Layout into INVISIBLE, but my capture goes black, if I capture my app if it comes out perfect, but I want to capture other apps, any ideas? ... I show you my method ..
public void addListenerOnButton4() {
Button btnTakeScreenshot = (Button) findViewById(R.id.share);
btnTakeScreenshot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
takeScreenshot();
}
});
}
public void takeScreenshot() {
RelativeLayout ln = (RelativeLayout) findViewById(R.id.Layout);
ln.setBackgroundColor(Color.TRANSPARENT);
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
// image naming and path to include sd card appending name you choose for file
String mPath = (Environment
.getExternalStoragePublicDirectory(Environment
.DIRECTORY_DOWNLOADS) +File.separator+now+"ScreenShoot.jpg");
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
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();
} catch (Throwable e) {
// Several error may come out with file handling or OOM
e.printStackTrace();
}
}