Android:如何判断相机何时被激活 [英] Android: how to tell when the camera is activated

查看:724
本文介绍了Android:如何判断相机何时被激活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我撰写的Android应用程式可供使用者在背景中执行,以侦测相机何时开启(由使用者或其他应用程式启用)。这也应该检测,即使在其他应用程序(如Facebook,instagram)不使用默认的Android相机应用程序的情况下。



我一直在搜索,但没有看到在相机被激活时发送的任何广播。到目前为止,我已经看到有Camera.open(),如果相机已被另一个应用程序使用,则抛出一个RuntimeException。所以一种方法是保持轮询Camera.open(),但它真的很贵。有更好的选择吗?



感谢



编辑:对不起,我没有提到它,想要做的是创建某种相机使用日志:什么时候打开/关闭,持续时间有多长等。

解决方案

内部发生的事情是Camera API与CameraService会话和CameraService有mBusy变量,它跟踪相机是否忙。没有API可以让这个mBusy标志退出服务(不调用open())



我可能是错的,因为我只是看了一下。 >

您可以下载Android源代码(http://source.android.com/),并自己仔细看看。



您可能感兴趣的文件是:



\frameworks\base\services\camera\libcameraservice\CameraService.cpp



\frameworks\base\libs\camera\Camera.cpp



\frameworks\base\\ \\core\java\android\hardware\Camera.java



\frameworks\base\core\jni\android_hardware_Camera.cpp

p>

另一个想法。尝试查看日志。在这种情况下,如果未针对Camera服务/ API关闭日志,则可以解析日志以检查相机何时开启或关闭。但是,它可能无法在OS 4.1中工作,因为Google只读取系统日志。


I'm writing an Android app that the user can run in the background to detect when the camera is turned on(by the user, or by other apps). This should also detect even in the scenario where other apps (like facebook, instagram) do not use the default android camera app.

I've been searching but haven't seen any broadcasts that are sent whenever the camera is activated. So far, I've seen that there's Camera.open() that throws a RuntimeException if the camera is already in use by another app. So one way is to keep polling Camera.open(), but it's really expensive. Is there a better alternative?

Thanks

Edit: Sorry i didn't mention it clearly but what I want to do is to create some kind of camera usage log: what time it was turned on/off, how long was the duration, etc..

解决方案

What happens internally is Camera API talks to CameraService and CameraService has mBusy variable which tracks whether camera is busy or not. And there is no API to get this mBusy flag out of service (without calling open())

I may be wrong, because I just glanced over it.

You can download Android source code (http://source.android.com/) and take a closer look yourself.

Files which could be interesting for you are:

\frameworks\base\services\camera\libcameraservice\CameraService.cpp

\frameworks\base\libs\camera\Camera.cpp

\frameworks\base\core\java\android\hardware\Camera.java

\frameworks\base\core\jni\android_hardware_Camera.cpp

One other idea. Try to look in the logs. In the case, if logs aren't turned off for Camera services/API, you can parse the logs to check when the camera was turned on or off. However, it may not work in OS 4.1, because Google limited reading of system logs.

这篇关于Android:如何判断相机何时被激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆