I want to access the flutter activity's decorView in my native code. I created a plugin which give me access to the apis in the android native code. One of the api is
public void setActivity(Activity activity){
Log.d("ActivityFromFlutter", activity.getLocalClassName());
...
...
}
I am using it like this in my flutter plugin:
private void setupPlugin(Context context, BinaryMessenger messenger, Registrar registrar) {
if (registrar != null) {
this.activity = ((Activity) registrar.activeContext());
this.nativeSdk.setActivity(this.activity);
}
}
Now I am getting the correct activity from the flutter plugin. But when I create bitmap image from activity.getWindow().getDecorView()
, I am getting a all white blank image.
To create bitmap from activity, I am using Canvas
DecorView decorView = activity.getWindow().getDecorView();
Bitmap bitmap = Bitmap.createBitmap(decorView.getMeasuredWidth(), decorView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
decorView.layout(0, 0, _window.getDecorView().getMeasuredWidth(), decorView.getMeasuredHeight());
decorView.draw(canvas);
So bitmap
I am getting is blank, but my Flutter Activity has multiple widgets.
I tried to implement ActivityAware
and used the override methods to get activity, but those methods didn't even execute.
How do I capture those?