flash torch functionality not working through app-widget in nexus 5

天涯浪子 提交于 2019-12-22 08:11:33

问题


Flash is turning-on fine from application (added surface_view to the layout), when I try to turn-on flash through app-widget it's not working. I used Camera and SurfaceView Here is the code I am using

Camera mCamera;
SurfaceView preview;
mCamera = Camera.open();
mCamera.setPreviewDisplay(preview.getCameraHolder());
Parameters params = mCamera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(params);  
mCamera.startPreview();

Added permission and features in Manifest are:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:name="android.hardware.camera.flash" android:required="false" />

回答1:


The camera needs a surface to cling to in order to open the
Flashlight..however SurfaceView cannot be applied to a widget. So this is what you need to.....

Add this to your turnFlashOn code:

try {
mCamera.setPreviewTexture(new SurfaceTexture(0));
} catch (IOException e) {
e.printStackTrace();
}

Also, remove all references to surfaceview in your code as it is not applicable in a widget



来源:https://stackoverflow.com/questions/21284473/flash-torch-functionality-not-working-through-app-widget-in-nexus-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!