gpt4 book ai didi

java - Android Flash 切换按钮崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 13:53:36 24 4
gpt4 key购买 nike

App is working fine in four different devices. but client is facing crash on flash buttton ON/OFF on Xperia z2.

主要 Activity

btnFlash.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
Toast.makeText(context, "Flash is toggled", Toast.LENGTH_LONG).show();

if(CameraPreview.isFlashOn)
{
CameraPreview.FlashOff(camera);

CameraPreview.isFlashOn = false;
}
else
{
CameraPreview.isFlashOn = true;

CameraPreview.FlashOn(camera);
}
}
});

相机预览

  public static boolean isFlashOn =false; // 

public static void FlashOn(Camera mCamera)
{
// Get Camera Params for customisation
Camera.Parameters parameters = mCamera.getParameters();

// Check Whether device supports AutoFlash, If you YES then set
// AutoFlash
List<String> flashModes = parameters.getSupportedFlashModes();

if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_TORCH))
{
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
}
else if (flashModes.contains(Parameters.FLASH_MODE_ON))
{
parameters.setFlashMode(Parameters.FLASH_MODE_ON);
}
mCamera.setParameters(parameters);
mCamera.startPreview();
}

public static void FlashOff(Camera mCamera)
{
// Get Camera Params for customisation
Camera.Parameters parameters = mCamera.getParameters();

// Check Whether device supports AutoFlash, If you YES then set
// AutoFlash
List<String> flashModes = parameters.getSupportedFlashModes();
if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_OFF))
{
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
}
mCamera.setParameters(parameters);
mCamera.startPreview();
}

崩溃报告。

me_idx 0, stream type 9
W/ActivityManager( 973): Activity pause timeout for ActivityRecord{45328828 u0
aus.xray.cam/.MainActivity2 t153 f}
D/mm-camera-intf( 9138): mm_stream_read_msm_frame: VIDIOC_DQBUF buf_index 6, fra
me_idx 840, stream type 1
I/mm-camera( 473): mct_pipeline_process_set:command=8000013
I/mm-camera( 473): pproc_module_handle_reprocess_offline:1318 input buf fd 126
type 4 size 462848
D/mm-camera-intf( 9138): mm_stream_read_msm_frame: VIDIOC_DQBUF buf_index 0, fra
me_idx 0, stream type 9
D/CustomizationProcess( 3778): dismissCustomizationDialog:true
I/WindowManager( 973): Screen frozen for +307ms due to Window{44e24b48 u0 Statu
sBar}
D/mm-camera-intf( 9138): mm_stream_read_msm_frame: VIDIOC_DQBUF buf_index 0, fra
me_idx 841, stream type 1
I/mm-camera( 473): mct_pipeline_process_set:command=8000013
I/mm-camera( 473): pproc_module_handle_reprocess_offline:1318 input buf fd 120
type 4 size 462848
D/mm-camera-intf( 9138): mm_stream_read_msm_frame: VIDIOC_DQBUF buf_index 1, fra
me_idx 0, stream type 9
^C
C:\adb>

最佳答案

应muku的要求。我自己回答了。用于切换闪光灯

flashBtn.setOnClickListener(new OnClickListener()
{
@Override
public onClick(View view)
{
if(cameraView!=null)//cameraView is the CameraPreview.class
{
if(cameraView.isFlashOn() && isFlashRunning)
{
cameraView.FlashOff(camera);

isFlashRunning = false;
}
else
{
cameraView.FlashOn(camera);

isFlashRunning = true;
}
}
});

FlashOn 和 FlashOff 方法是

public void FlashOn(Camera mCamera) throws RemoteException
{
// Get Camera Params for customisation
Camera.Parameters parameters = mCamera.getParameters();

// Check Whether device supports AutoFlash, If you YES then set
// AutoFlash
List<String> flashModes = parameters.getSupportedFlashModes();

if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_TORCH))
{
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);

isFlashOn = true;
}
else if (flashModes.contains(Parameters.FLASH_MODE_ON))
{
parameters.setFlashMode(Parameters.FLASH_MODE_ON);

isFlashOn = true;
}

mCamera.setParameters(parameters);

mCamera.startPreview();

//mCamera.autoFocus(null); // may be this is problem
}



public void FlashOff(Camera mCamera) throws RemoteException
{
// Get Camera Params for customisation
Camera.Parameters parameters = mCamera.getParameters();

// Check Whether device supports AutoFlash, If you YES then set
// AutoFlash
List<String> flashModes = parameters.getSupportedFlashModes();

if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_OFF))
{
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);

isFlashOn = false;
}

mCamera.setParameters(parameters);

mCamera.startPreview();
}

关于java - Android Flash 切换按钮崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30053090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com