简体   繁体   English

强制关闭Android Custom Camera应用程序

[英]Force close for Android Custom Camera app

I am developing an android custom camera application without using the intent (to avoid getting android's built in camera features). 我正在开发一个Android自定义相机应用程序,而不使用意图(以避免获得Android内置的相机功能)。 I have enabled auto focus feature in my app. 我在我的应用中启用了自动对焦功能。 I am taking the picture on press of a keyVolume Button. 我按下了一个keyVolume按钮拍照。 And I am using the below code for setting the parameters. 我正在使用以下代码来设置参数。

    Camera.Parameters p = camera.getParameters();
    camera.autoFocus(autoFocusCallback);
    p.setFocusMode(Parameters.FOCUS_MODE_AUTO);
    camera.setParameters(p1);
    camera.takePicture(shutterCallback, rawCallback, jpgCallback);


    void setHandler(Handler autoFocusHandler, int autoFocusMessage) 
    {
           this.autoFocusHandler = autoFocusHandler;
           this.autoFocusMessage = autoFocusMessage;
    }

    private AutoFocusCallback autoFocusCallback = new AutoFocusCallback() 
    {
         private Object success;
         @Override
         public void onAutoFocus(boolean autoFocusSuccess, Camera camera)
         {  
              if (autoFocusHandler != null)
              {
                    Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success);
                    autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS);
                    autoFocusHandler = null;
              }
              else
              {

              }
         }
};

But the problem is that, this code works fine only for LG phone. 但问题是,此代码仅适用于LG手机。 and i am getting force close on all other phones after running it. 并且在运行之后我将在所有其他手机上关闭。

And the Error Log looks like this 错误日志看起来像这样

http://textuploader.com/?p=6&id=kOc9G http://textuploader.com/?p=6&id=kOc9G

Not getting where i am going wrong. 没有得到我错的地方。 Please Help! 请帮忙! Thanks! 谢谢!

Different phones have different camera params. 不同的手机有不同的相机参数。 Check if mode available befire actually setting it. 检查模式是否可用实际设置befire。

For example, in your case there is public List<String> getSupportedFocusModes () function of Camera.Parameters class. 例如,在您的情况下,有Camera.Parameters类的public List<String> getSupportedFocusModes ()函数。

Afaik, cheap phones like acer or zte or some others, have very weak programming support for their cameras. Afaik,便宜的手机,如宏碁或中兴或其他一些,对他们的相机的编程支持非常弱。

UPD: code sample UPD:代码示例

    Camera.Parameters p = camera.getParameters();
    List<String> modes = p.getSupportedFocusModes();
    if(modes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
    {
        p.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
        camera.setParameters(p);
        camera.autoFocus(autoFocusCallback);

    }
    else
    {
        // this is default focus mode if autofocus unsupported.
        // also, we should not call camera.autoFocus(autoFocusCallback) here
        p.setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED);
        camera.setParameters(p);
    }

you are using 您正在使用

 Camera.Parameters p = camera.getParameters();

so replace 所以更换

 camera.setParameters(p1);

with

 camera.setParameters(p);

I think this should help you.... 我想这应该对你有帮助....

Camera.Parameters p = camera.getParameters();
List<Size> sizes = p.getSupportedPictureSizes();
// Choose any one you want among sizes
size = sizes.get(0);
p.setPictureSize(size.width, size.height);
camera.setParameters(p);

Don't use "p.setFocusMode(Parameters.FOCUS_MODE_AUTO);" 不要使用“p.setFocusMode(Parameters.FOCUS_MODE_AUTO);” line. 线。

By default focus mode will be FOCUS_MODE_AUTO. 默认情况下,焦点模式为FOCUS_MODE_AUTO。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM