手电筒 (LED BACK) 开/关,相机无效 HTC
我正在练习并尝试更换 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论