手电筒 (LED BACK) 开/关,相机无效 HTC

发布于 2024-12-17 20:07:57 字数 2289 浏览 1 评论 0原文

我正在练习并尝试更换 HTC 背面的手电筒(手电筒)。 但我没有相机访问权限,我在清单中添加了以下内容:


;
 >

它可能非常简单和愚蠢,但是谷歌和StackOverflow没有给我一个解决方案,所以有人可以告诉我我做错了什么吗? 这是我的活动文件:

import android.app.Activity; 
import android.content.Intent; 
import android.hardware.Camera; 
import android.hardware.Camera.Parameters;
import android.os.Bundle; 
import android.widget.*; 
import android.view.View; 
import android.util.Log; 
import java.util.List;

public class FlashlightActivity extends Activity {      
  private Camera mCamera;

  /** Called when the activity is first created, just a titlescreen. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ImageButton titlescreen = (ImageButton)findViewById(R.id.titlescreen);
    titlescreen.setOnClickListener(new View.OnClickListener()  {
      public void onClick(View v){
        TurnFlashOff();
        if (mCamera==null){ 
          finish();}
        else {
          Intent go = new Intent(TurnMeOnFlashlightActivity.this,TMO_App.class);
          startActivity(go);
        }
      }
    });
    Log.d("TurnMeOn", "startpage");
  }

  private void TurnFlashOff(){
    if(mCamera != null){
      mCamera = Camera.open();
      Parameters params = mCamera.getParameters();
      List<String> flashModes = params.getSupportedFlashModes();

      if (flashModes.contains(Parameters.FLASH_MODE_TORCH)) {
        params.setFlashMode(Parameters.FLASH_MODE_OFF);
        mCamera.setParameters(params); 
        mCamera.release();
        mCamera = null;
      } else {
        Toast.makeText(TurnMeOnFlashlightActivity.this, R.string.FlashNoSupport, Toast.LENGTH_LONG).show();
        mCamera.release();
        mCamera = null;
      } 
    } else {
      Toast.makeText(TurnMeOnFlashlightActivity.this, R.string.FlashNoSupport, Toast.LENGTH_LONG).show();
    }
  }
}

I'm practicing and trying to change the flashlight (torch) on the back of my HTC.
But I get no camera access, I put in the manifest the following:

<uses-permission android:name="android.permission.FLASHLIGHT"
   android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
   android:protectionLevel="normal"/>
<uses-permission android:name="android.permission.CAMERA"/>
 <uses-feature android:name="android.hardware.camera.flash" />

It can be very simple and stupid, but google and StackOverflow didn't gave me a solution, so can anybody tell me what I'm doing wrong?
This is my activity file:

import android.app.Activity; 
import android.content.Intent; 
import android.hardware.Camera; 
import android.hardware.Camera.Parameters;
import android.os.Bundle; 
import android.widget.*; 
import android.view.View; 
import android.util.Log; 
import java.util.List;

public class FlashlightActivity extends Activity {      
  private Camera mCamera;

  /** Called when the activity is first created, just a titlescreen. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ImageButton titlescreen = (ImageButton)findViewById(R.id.titlescreen);
    titlescreen.setOnClickListener(new View.OnClickListener()  {
      public void onClick(View v){
        TurnFlashOff();
        if (mCamera==null){ 
          finish();}
        else {
          Intent go = new Intent(TurnMeOnFlashlightActivity.this,TMO_App.class);
          startActivity(go);
        }
      }
    });
    Log.d("TurnMeOn", "startpage");
  }

  private void TurnFlashOff(){
    if(mCamera != null){
      mCamera = Camera.open();
      Parameters params = mCamera.getParameters();
      List<String> flashModes = params.getSupportedFlashModes();

      if (flashModes.contains(Parameters.FLASH_MODE_TORCH)) {
        params.setFlashMode(Parameters.FLASH_MODE_OFF);
        mCamera.setParameters(params); 
        mCamera.release();
        mCamera = null;
      } else {
        Toast.makeText(TurnMeOnFlashlightActivity.this, R.string.FlashNoSupport, Toast.LENGTH_LONG).show();
        mCamera.release();
        mCamera = null;
      } 
    } else {
      Toast.makeText(TurnMeOnFlashlightActivity.this, R.string.FlashNoSupport, Toast.LENGTH_LONG).show();
    }
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文