简体   繁体   中英

Camera2 sample app crashes on Lollipop device

I am trying to run Camera2 sample application https://github.com/googlesamples/android-Camera2Basic on Samsung SM-G900V (Galaxy S5) which is running Lollipop 5.0 API level 21.

However the application crashes - with following exception. android.camera2basic E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NoSuchMethodError: No virtual method checkSelfPermission(Ljava/lang/String;)I in class Landroid/app/Activity; or its super classes (declaration of 'android.app.Activity' appears in /system/framework/framework.jar)

If I am reading google's documentation right API 21 should have support for Camera2 APIs.I have also tried same thing with Android emulator and getting similar crash. Is Camera2 API supposed to work on API21 devices?

The crash doesn't have anything to do with the camera2 package.

The problem is with the method you are calling to check runtime permissions: the one you are using was only added in API Level 23. This article provides methods to safely check runtime permissions on Android < 23, check the section titled

Use Support Library to make code forward-compatible

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM