问题描述
我面临与三星Galaxy Tab的一个问题。我想用相机的闪光灯作为火炬。
I'm facing to a problem with a Samsung Galaxy Tab. I want to use the camera flash as torch.
没有人知道如何启用它?
Does anyone know how to enable it ?
在此一code,工程启用/禁用对HTC Desire的相机闪光灯,但未能对三星Galaxy Tab。
Hereby a code that works to enable/disable the camera flash on a HTC Desire but fails on Samsung Galaxy Tab.
FlashLight.java:的
FlashLight.java :
package com.example.FlashLight;
import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class FlashLight extends Activity {
private final static String LOG_TAG = "FlashLight";
private Button mOnBtn;
private Button mOffBtn;
private Camera mCamera;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mOnBtn = (Button) findViewById(R.id.on_btn);
mOnBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
processOnClick();
}
});
mOffBtn = (Button) findViewById(R.id.off_btn);
mOffBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
processOffClick();
}
});
}
@Override
protected void onResume() {
super.onResume();
try{
mCamera = Camera.open();
} catch( Exception e ){
Log.e(LOG_TAG, "Impossible d'ouvrir la camera");
}
}
@Override
protected void onPause() {
if( mCamera != null ){
mCamera.release();
mCamera = null;
}
super.onPause();
}
private void processOffClick(){
if( mCamera != null ){
Parameters params = mCamera.getParameters();
params.setFlashMode( Parameters.FLASH_MODE_OFF );
mCamera.setParameters( params );
}
}
private void processOnClick(){
if( mCamera != null ){
Parameters params = mCamera.getParameters();
params.setFlashMode( Parameters.FLASH_MODE_TORCH );
mCamera.setParameters( params );
}
}
}
的AndroidManifest.xml:的
AndroidManifest.xml :
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".FlashLight"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
</manifest>
布局/ main.xml中:的
layout/main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/on_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Flash ON" />
<Button
android:id="@+id/off_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Flash OFF" />
</LinearLayout>
谢谢!
推荐答案
您没有做错什么。事实上,你正在做的一切是正确的。您遇到非常$在Android世界p $ pvalent设备特定问题。我发现以下行为模式的FLASH_MODE_TORCH:
You aren't doing anything wrong. In fact, you are doing everything correct. You are encountering a Device-Specific issue that is very prevalent in the Android world. I have found the following behavioral patterns for FLASH_MODE_TORCH:
- 在所有情况下
- 工作细
- 工作正常但不支持自动聚焦于
- 在根本不 工作
- Works fine in all cases
- Works fine, but not with autofocus on
- Doesn't work at all
无奈的是,getSupportedFlashModes()将返回FLASH_MODE_TORCH几乎所有的设备上时,只有极少数的真正支持。
Frustratingly, getSupportedFlashModes() will return FLASH_MODE_TORCH on nearly every device when only a handful actually support it.
此外,一些设备实现调酒的支持闪光模式。如果你通过Camera.Parameters你可以尝试设置闪光模式FLASH_MODE_ON,FLASH_MODE_AUTO或FLASH_MODE_RED_EYE,看看是否有任何工作。注 - 这是一个设备专用的劈
Also, some device implementations swizzle the supported flash modes. If you go through Camera.Parameters you can try setting the flash mode to FLASH_MODE_ON, FLASH_MODE_AUTO or FLASH_MODE_RED_EYE and see whether any of them work. Note - this is a device-specific hack.
我已经申请这些类型的错误的与谷歌有关的DroidX和Nexus S.他们关闭它作为一个设备特定问题。我要说的,希望有一个驱动程序或固件修复这种情况报告给三星,但他们的支持Android渠道的。
I have filed these types of bugs with Google regarding the DroidX and Nexus S. They closed it as a device-specific issue. I would say to report this to Samsung in hopes for a driver or firmware fix, but their Android support channels do not exist.
这篇关于如何使用相机闪光灯/ LED作为火炬在三星Galaxy Tab?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!