android api 21+ 摄像头2 api
android api 21+ camera2 api
我尝试 运行 这段代码,但它说在 framworke.jar
中找不到某些东西
super.onCreate(savedInstanceState);
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
String id = null;
try {
id = manager.getCameraIdList()[0];
} catch (CameraAccessException e) {
e.printStackTrace();
}
try {
manager.setTorchMode(id,true);
} catch (CameraAccessException e) {
e.printStackTrace();
}
但是我遇到了这个错误,
02-15 01:03:33.794 32378-32378/com.phenix.testcam E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.phenix.testcam, PID: 32378
java.lang.NoSuchMethodError: No virtual method setTorchMode(Ljava/lang/String;Z)V in class Landroid/hardware/camera2/CameraManager; or its super classes (declaration of 'android.hardware.camera2.CameraManager' appears in /system/framework/framework.jar)
at com.phenix.testcam.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
at android.app.ActivityThread.access0(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5373)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
请问我需要一些解释
setTorchMode() 已添加到 API 23 - API 21-22 设备将没有该方法。
我尝试 运行 这段代码,但它说在 framworke.jar
中找不到某些东西 super.onCreate(savedInstanceState);
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
String id = null;
try {
id = manager.getCameraIdList()[0];
} catch (CameraAccessException e) {
e.printStackTrace();
}
try {
manager.setTorchMode(id,true);
} catch (CameraAccessException e) {
e.printStackTrace();
}
但是我遇到了这个错误,
02-15 01:03:33.794 32378-32378/com.phenix.testcam E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.phenix.testcam, PID: 32378
java.lang.NoSuchMethodError: No virtual method setTorchMode(Ljava/lang/String;Z)V in class Landroid/hardware/camera2/CameraManager; or its super classes (declaration of 'android.hardware.camera2.CameraManager' appears in /system/framework/framework.jar)
at com.phenix.testcam.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
at android.app.ActivityThread.access0(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5373)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
请问我需要一些解释
setTorchMode() 已添加到 API 23 - API 21-22 设备将没有该方法。