I know there is same question on SO and I also know that question has one answer with two downvotes.
Here is what I'm doing to take a screenshot
private Bitmap takeScreenshot(){
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
I'm using these two methods to capture the screen, well it does work but only when the user is in the app but I'm using a floating widget and want to capture the screen where ever the user is in his phone just like a normal screenshot.
And I'm also recording the screen, which is what the app is about, so I may say that media projection is already in use.
How can I achieve this any idea or suggestions anything