I want to make Bitmap data from activity's output. Activity contains a fragment, and I can't modify it.
I don't want to activity to real screen and just want to make bitmap data. How can I do it.
I want to make Bitmap data from activity's output. Activity contains a fragment, and I can't modify it.
I don't want to activity to real screen and just want to make bitmap data. How can I do it.
I assume you want something like a screenshot of your activity.
In order to get the root view of your activity (what you're currently seeing), do this:
View view = getWindow().getDecorView().findViewById(android.R.id.content);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();
view.setDrawingCacheEnabled(false);
and then you'll have a Bitmap of your activity, referenced by the bitmap
variable.
Do what you want with that Bitmap, like saving it to a file.
If you wan to capture the Activity's View hierarchy to a Bitmap, try this:
View view = findViewById(android.R.id.content);
view.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);