Hi,
First of all, thank you for sharing the
MediaProjectionScreenShot library — it’s very useful.
I am trying to use it for
continuous screen capture (every few seconds) in a foreground service, but I’m facing an issue with the MediaProjection session lifecycle.
What works
- AskforPermission → works
- init(0,0,0) → works
- TakeScreenshot(True) → returns bitmap via ImageReady
- OCR works fine on the bitmap
Problem
For continuous capture:
oMediaProjectionScreenShot.init(0, 0, 0)
oMediaProjectionScreenShot.TakeScreenshot(True)
→ Screenshot works, but Android shows
“Start recording or casting?” popup every time
oMediaProjectionScreenShot.TakeScreenshot(False)
→ No popup (good), but
ImageReady stops firing after a few calls
What I need
I want to:
Ask permission ONCE
Keep MediaProjection session alive
Call TakeScreenshot repeatedly (e.g. every 3 seconds)
Receive ImageReady every time
NO repeated system popup
Question
Is there a way in this library to:
Keep a persistent MediaProjection session alive
Reuse the same VirtualDisplay / ImageReader
Avoid calling init() every time
Or is the current implementation designed to
stop/recreate projection per screenshot?
Environment
- B4A 11.50
- Android 11+ device
- Foreground service with:
android:foregroundServiceType="mediaProjection"
Suggestion
If possible, it would be great to have:
StartProjection() → once
CaptureFrame() → repeatedly
StopProjection() → manually
without triggering permission dialog again.
Thanks again for your work — any guidance would be really appreciated.