I want to build an app where I have to use MediaProjectionManager in a Service. But I can not solve it as 'startActivityForResult' can't use in Service class.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
I really want to do this from a service, which is how I found this question. This is the closest I've came up, so just throwing this out there, till a better answer comes along. Here's a way to do it from an activity that's almost like doing it from a service:
Then in your service when ever you need permission call
To make the activity invisible in your AndroidManifest.xml
Caveats:
For a brief second the application you're screenshooting will lose focus.
For a brief second your app will be the foreground app, so don't trip over your own shoelaces
Ok, I have managed to do this its not the cleanest of ways but works:
Note: Upon being called the startActivityForResult will be caught in the onActivityResult() in the Activity Class. You will need to override this function in the Activity and use the service reference to return back to the service class. Also you can unbind the Activity, from the service upon completion.
I hope this makes sense, sorry for not including any code. If you have any questions ill be glad to help you in further detail.