mtsahakis / MediaProjectionDemo

One Activity sample app of using Android Lollipop MediaProjection API to capture device screenshots
Other
210 stars 76 forks source link

Can we record screen in service ? #21

Closed tmehta813 closed 3 years ago

tmehta813 commented 4 years ago

As in my app we don't have any activity, Can we record screen in service ?

mtsahakis commented 4 years ago

I had done something similar at some point, see

https://gist.github.com/mtsahakis/a4dca46b80cb8ac2cd100a7a52f65b1d https://gist.github.com/mtsahakis/5c709bbd9cf5074a377e6e3114c0e4b6

Hope it helps,

Manos

tmehta813 commented 4 years ago

Thank you for you response, Can we also control it from notification?

mtsahakis commented 4 years ago

I would assume so, just start the service from the notification https://stackoverflow.com/questions/6422319/start-service-from-notification

Rich2020 commented 4 years ago

Hmm, my code won't compile when I use PixelFormat.RGBA_8888. I have to change to ImageFormat, but then I get exceptions when image = mImageReader.acquireLatestImage();. I've been through all the comments in a SO post that you created, but it is still not working for me. I'd love it if you can take a look and give me a hand. Thanks!

mtsahakis commented 3 years ago

It should compile as it is just a warning. I added a @SuppressLint("WrongConstant") annotation. If you look into the source code of ImageReader, it states

`* @param format The format of the Image that this reader will produce. This

So could be something wrong with the @Format annotation.