I making ane which makes screenshot of application. But I always getting black rectangle.
public class TakeScreenshot implements FREFunction {
@Override
public FREObject call(FREContext context, FREObject[] args) {
try {
View view = context.getActivity().getWindow().getDecorView().getRootView();
view.setDrawingCacheEnabled(true);
Bitmap cachedBitmap = Bitmap.createBitmap(view.getDrawingCache());
Bitmap bitmap = cachedBitmap.copy(cachedBitmap.getConfig(), false);
FREBitmapData bmd = (FREBitmapData)args[0];
bmd.acquire();
bitmap.copyPixelsToBuffer(bmd.getBits());
bmd.release();
bmd.invalidateRect(0,0, bitmap.getWidth(), bitmap.getHeight());
return bmd;
} catch (FREWrongThreadException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Guess, the problem is in taking correct View from FREContext. Have tried different ways to take View with same result:
View view = context.getActivity().getWindow().getDecorView();
View view = context.getActivity().findViewById(android.R.id.content);
View view = context.getActivity().findViewById(android.R.id.content).getRootView();