簡體   English   中英

LED手電筒不適用於三星Galaxy Nexus

[英]LED Flashlight does not work on Samsung Galaxy Nexus

我有以下問題:我的手電筒應用程序在我的三星Galaxy S2上工作正常但不幸的是沒有在三星Galaxy Nexus上(問題:手電筒忽略按鈕點擊 - >沒有反應,沒有光線,沒有崩潰,也沒有異常)。 我讀過“Galaxy Nexus上的LED手電筒可以通過哪種API控制?” 這里在stackoverflow但它沒有幫助我,因為我的問題仍然發生。 這是我控制燈光的代碼片段:

final Button FlashLightControl = (Button)findViewById(R.id.ledbutton);
FlashLightControl.setOnClickListener(new Button.OnClickListener()
{
        public void onClick(View arg) 
        {
            if(camera != null)
            {
                //in case light is on we will turn it off
                parameters = camera.getParameters();
                parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
                camera.setParameters(parameters);
                camera.stopPreview();
                camera.release();
                camera = null;
            }
            else
            {
                // light is off - we turn it on
                camera = Camera.open();
                parameters = camera.getParameters();
                parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
                camera.setParameters(parameters);
                camera.startPreview();
            }
        }}); 

有任何想法嗎? 為了完整起見 - 這些是我添加到Androidmanifest.xml的權限:

    <uses-feature android:name="android.hardware.camera.flash" />
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

有人可以幫忙嗎?

親切的問候,CarpeTemporem

我也遇到了同樣的問題,但我試圖從服務中打開LED,所以我無法使用1x1 SurfaceView。 這就是我做的工作。

private void turnLEDOn() throws IOException
{
    // In order to work, the camera needs a surface to turn on.
    // Here I pass it a dummy Surface Texture to make it happy.
    camera = Camera.open();
    camera.setPreviewTexture(new SurfaceTexture(0));
    camera.startPreview();
    Parameters p = camera.getParameters();
    p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    camera.setParameters(p);
}

private void turnLEDOff()
{
    if (camera != null)
    {
        // Stopping the camera is enough to turn off the LED
        camera.stopPreview();
        camera.release();
        camera = null;
    } else
        throw new NullPointerException("Camera doesn't exist to turn off.");

}

SurfaceTexture在API Level 11(Android 3.0)中添加,因此它只適用於Honeycomb或更新版本。 對於較舊的API級別,您可以在另一個答案中堅持使用SurfaceView技巧。

我遇到了同樣的問題,並通過使用1px寬度和1px高度的Surface View解決了這個問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM