Android:BroadcastReceiver 意图检测拍摄的相机照片吗?
我正在开发一个 Android 应用程序,每次用手机拍摄新图像时都需要执行一个操作。我不想在应用程序中拍摄图像,而是在相机应用程序拍摄图像并将其保存到 SD 卡时执行一些操作。现在,我已经实现了一个 BroadcastReceiver,当前正在侦听“android.intent.action.CAMERA_BUTTON”。然而,当我想要的时候,这似乎并没有被调用。我尝试在自己的手机上调试应用程序,并在 BroadcastReceiver 的 OnReceive 方法的第一行添加换行符,但它从未到达该代码。
有谁知道我应该倾听的正确意图是什么?或者使用 BroadcastReceiver 甚至不是实现此目的的最佳方法? (例如,是否有更好的方法来完成此操作,例如监听新图像何时保存到卡中)?
谢谢!
更新:我的手机 (HTC Eris) 上确实有轨迹球,那么以这种方式拍照是否有可能不会作为“相机按钮”发送?如果是这样,对于没有“相机按钮”、而是像轨迹球之类的东西的手机是否有解决方法?
I'm working on an Android application which needs to perform an action each time a new image is taken with the phone. I don't want to take the image within my application, but rather perform some action when the Camera app takes an image and saves it to the SD card. Right now, I've gotten a BroadcastReceiver implemented that's currently listening for "android.intent.action.CAMERA_BUTTON". However, this doesn't seem to get called when I'm wanting it to. I've tried to debug the application on my own phone with a linebreak on the first line of the BroadcastReceiver's OnReceive method, but it never reaches that code.
Does anyone know what the correct intent for which I should be listening is? Or is using a BroadcastReceiver not even the best way to do this? (For example, is there a better way to accomplish this such as listening for when a new image is saved to the card)?
Thanks!
Update: I do have a Trackball on my phone (HTC Eris), so is it possible that taking photos that way doesn't get sent as "Camera Button"? If so, is there a workaround for a phone without a "Camera Button", but rather something like a Trackball?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
仅当前台活动不消耗该事件时才会广播。
That only gets broadcast if the foreground activity does not consume the event.
这是一个很老的问题,如果有人仍然需要该解决方案,请尝试使用
作为你的意图过滤器
它将在其onReceive()函数的intent.getData()中返回图像的Uri
希望它有帮助
Quite an old question, if anyone still needs the solution try using
as your intent filter
It will return the Uri of the image in intent.getData() of its onReceive() function
Hope it helps
试试这个,这对我有用
try this one this works for me