I used the accessibility service to expand the notifications bar on receiving notifications. I'm trying to take the screenshot of the Notification in the notification drawer.
From the documentation of the Accessibility service it possible to take the screenshot of the device from Android P only.
is there any other possibilities to take the screenshot of the notification drawer as my App is not in the foreground. It is running in the background
Thanks in advance.
Yes, you can do this, though it's tricky. The trick is to utilize the Media Projection Manager combined with an Activity that is in the same package as your Service. You can then utilize the MediaProjectionManager's ability to capture images, along with shared storage, to grab screenshots.
In the on create of your AccessibilityService do this:
Then your ImageCaptureActivity will just be a standard activity, but won't have any UI. It will just manage the interactions with the Media Projection Manager. In my case, it ends up being a one pixel clear dot. This is actually pretty difficult to set up. I'll copy my ImageCaptureActivity. This probably won't completely work for you, but when I was digging into this, I found this process terribly poorly documented. I have not doctored this up, but maybe it will help you.
NOTE: This approach will work as far back as Android 5.0.