更新** 全班:
public class TorchActivity extends Activity {
ImageButton btnSwitch;
private Camera camera;
private boolean isFlashOn;
private boolean hasFlash;
Parameters params;
MediaPlayer mp;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// flash switch button
btnSwitch = (ImageButton) findViewById(R.id.btnSwitch);
...
...
// get the camera
getCamera();
...
// Switch button click event to toggle flash on/off
btnSwitch.setOnClickListener(new View.OnClickListener() {
@Override
...
});
}
// Get the camera
private void getCamera() {
if (camera == null) {
try {
camera = Camera.open(); //The method open() is undefined for the type Camera
params = camera.getParameters(); //Add cast to 'camera'
} catch (RuntimeException e) {
Log.e("Camera Error. Failed to Open. Error: ", e.getMessage());
}
}}
这里我创建了一个手电筒应用程序,只需通过相机应用程序访问Flash权限。 我无法向'相机'提供演员...... 我怎么能这样做?
SLOUTION:
这些错误是由使用正确导入后使用Import.android.graphics.camera
代替Import.android.hardware.camera
引起的,没有任何错误。
答案 0 :(得分:0)
Camera theCamera = camera;
if (theCamera == null) {
theCamera = Camera.open();
if (theCamera == null) {
throw new IOException();
}
camera = theCamera;
}
尝试以这种方式打开相机。如果你得到例外 - 你不能使用相机(可能相机已经打开并且未关闭)。您也可以随意使用
修改强> 似乎你的问题是另一个问题: 你的导入应该是this class(android.hardware.Camera),但不是this class(android.graphics.Camera) 检查
答案 1 :(得分:0)
这些错误是由使用Import.android.graphics.camera
代替Import.android.hardware.camera
引起的
使用正确导入后,没有任何错误。