Turn on/off flashlight while app is minimized

早过忘川 提交于 2019-12-06 11:44:36

问题


In my application I have an activity and a service. The service continously manages some data. In certain cases the service sends a broadcast request to the activity to turn on flashlight.

This works very well. However it does not work when app is minimized (manually or by incomming call). As soon as I bring the app back to the front it starts to work again.

As I observed the log I saw that the service is still running when app is minimized. However since the activity is not present anymore the camera object cannot be accessed to activate the flashlight. But there is no error in the log.

Why is the flashlight not activated? How can the flashlight be activated when the app is minimized?


回答1:


Only the foreground activity can hold the camera. From the Google documentation:

"If your application does not properly release the camera, all subsequent attempts to access the camera, including those by your own application, will fail and may cause your or other applications to be shut down."

You can try claiming it on the service instead, but I suspect that won't work well. It just really wasn't designed to work this way.



来源:https://stackoverflow.com/questions/14901236/turn-on-off-flashlight-while-app-is-minimized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!