为什么相机无法启动,每次?无法启动、相机

由网友(风鹤)分享简介:我想眨眼手电筒来电。每当这个code会在服务方法,即它的运行良好,它的启动服务不错,但问题是它无法启动相机服务每次。如果摄像机正在运行闪烁不停止,如果呼叫状态的变化。我怎么能启动相机每次和停止,如果闪烁的呼叫状态的变化?在code我用... 在清单<使用-权限的Andr​​oid:名称=android.perm...

我想眨眼手电筒来电。每当这个code会在服务方法,即它的运行良好,它的启动服务不错,但问题是它无法启动相机服务每次。如果摄像机正在运行闪烁不停止,如果呼叫状态的变化。我怎么能启动相机每次和停止,如果闪烁的呼叫状态的变化? 在code我用...

在清单

 <使用-权限的Andr​​oid:名称=android.permission.READ_PHONE_STATE/>
        <使用-权限的Andr​​oid:名称=android.permission.CAMERA/>
        <使用-权限的Andr​​oid:名称=android.permission.FLASHLIGHT/>
 

在服务

 字符串状态= intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        如果(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
        尝试 {
            凸轮= Camera.open();
            p值= cam.getParameters();

            字符串MyString的=0101010101010101010101010101010101010101010101011;
            长blinkDelay = 150;
            cam.setParameters(对);

            的for(int i = 0; I< myString.length();我++){

                     如果(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){

                打破;

                }否则,如果(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
                打破;
                }

                如果(myString.charAt(ⅰ)=='0'){
                    p.setFlashMode(Parameters.FLASH_MODE_TORCH);
                    cam.setParameters(对);
                } 其他 {
                    p.setFlashMode(Parameters.FLASH_MODE_OFF);
                    cam.setParameters(对);
                }
                尝试 {
                    视频下载(blinkDelay);
                }赶上(例外五){
                    Log.d(标签,e.toString());
                    p.setFlashMode(Parameters.FLASH_MODE_OFF);
                    cam.setParameters(对);
                }
            }
        }赶上(例外五){
            // TODO:处理异常
            Log.d(在catch1标签);
            Log.d(标签,e.toString());

    }
}否则,如果(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
    cam.release();
    stopSelf();
    }否则,如果(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
        cam.release();
        stopSelf();
    }
}
 
vivo手机相机无法启动

在logcat的没有停止,它仍在运行,疯狂的是,我宣布我得到这个标记

  03-11 23:11:08.129:W / CameraService(133):CameraService ::连接X(PID 942)拒绝(现有的客户端)。
03-11 23:11:08.139:D /疯狂的(942):在catch1
03-11 23:11:08.139:D /疯狂的(942):java.lang.RuntimeException的:无法连接到摄像机服务
 

解决方案

如果您检查出的相机文档,即打开摄像头可以抛出一个理由一个的RuntimeException 的是,另一个进程正在使用的摄像头,这是什么错误日志似乎预示。检查其他进程正在运行什么,并确保没有其他人在使用相机(你也应该正确地处理这个错误)。

您也应该确保的您的应用程序调用发布()相机,让你不阻止使用其他应用程序吧。

I want to blink flashlight on incoming call. Everytime this code is going in service method i.e its running fine, its starting the service fine but the problem is its unable to start camera service everytime. If camera is running the blinking is not stopping if the call state changes. How could i start camera everytime and stop the blinking if the call state changes?? The code i used...

in manifest

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
        <uses-permission android:name="android.permission.CAMERA"/>
        <uses-permission android:name="android.permission.FLASHLIGHT"/>

in service

    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
        try {
            cam = Camera.open();
            p = cam.getParameters();

            String myString = "0101010101010101010101010101010101010101010101011";
            long blinkDelay = 150;
            cam.setParameters(p);

            for (int i = 0; i < myString.length(); i++) {

                     if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){

                break;                  

                }else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
                break;  
                }               

                if (myString.charAt(i) == '0') {
                    p.setFlashMode(Parameters.FLASH_MODE_TORCH);
                    cam.setParameters(p);
                } else {
                    p.setFlashMode(Parameters.FLASH_MODE_OFF);
                    cam.setParameters(p);
                }
                try {
                    Thread.sleep(blinkDelay);
                } catch (Exception e) {
                    Log.d(tag, e.toString());
                    p.setFlashMode(Parameters.FLASH_MODE_OFF);
                    cam.setParameters(p);
                }
            }
        }catch (Exception e) {
            // TODO: handle exception
            Log.d(tag, "in catch1");
            Log.d(tag, e.toString());

    }
}else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
    cam.release();
    stopSelf();
    }else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
        cam.release();
        stopSelf();
    }
}

The logcat is not stopping and it is still running , crazy is the tag that i declared i got this

    03-11 23:11:08.129: W/CameraService(133): CameraService::connect X (pid 942) rejected (existing client).
03-11 23:11:08.139: D/crazy(942): in catch1
03-11 23:11:08.139: D/crazy(942): java.lang.RuntimeException: Fail to connect to camera service

解决方案

If you check out the Camera documentation, one reason that opening the camera could throw a RuntimeException is that another process is using the camera, which is what the error log seems to indicate. Check what other processes are running and make sure nothing else is using the camera (you should also be properly handling this error).

You should also make sure your application is calling release() on the camera, so that you aren't blocking other applications from using it.

阅读全文

相关推荐

最新文章