我怎样才能释放相机时,另一个应用程序请求呢? [英] How can I release the camera when another application requests it?

查看:272
本文介绍了我怎样才能释放相机时,另一个应用程序请求呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序都使用相机:

I have two applications that both use the camera:


  1. 我已经开发了一个手电筒的应用程序

  2. 相机应用

手电筒应用打开相机,开启闪光灯,并在后台运行。但是,如果启动相机应用,而手电筒上,有一个在相机应用一个错误,因为相机已在使用的手电筒应用程序:

The flashlight app opens the camera, turns on the flash, and runs in the background. However, if you start the camera app while the flashlight is on, there is an error in the camera app since the camera is already in use by the flashlight app:

无法获取设备

在手电筒的应用程序,我怎么能释放相机时,另一个应用程序请求呢?

In the flashlight app, how can I release the camera when another app requests it?

推荐答案

在你的手电筒的应用程序,创建一个广播接收器。为了您的manifest.xml,添加

In your flashlight app, create a broadcast receiver. To your manifest.xml, add

<receiver android:name="CameraRequestReceiver" >
     <intent-filter>
         <action android:name="com.yourPackage.flashlight" />
     </intent-filter>
</receiver>

和创建一个广播接收器

public class CameraRequestReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
        //release camera here
    }
}

如果您打开相机应用和相机被锁定,只需发送一个广播,以你的手电筒的应用程序:

If you open the camera application and the camera is locked, simply send a broadcast to your flashlight app:

Intent intent = new Intent();
intent.setAction("com.yourPackage.flashlight");
sendBroadcast(intent); 

更多关于BroadcastReceivers:的http://www.vogella.com/tutorials/AndroidBroadcastReceiver/article.html#ownreceiver

这篇关于我怎样才能释放相机时,另一个应用程序请求呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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