안드로이드

코틀린으로 카메라 켜기 (intent)

고태광이 2019. 3. 2. 15:37

코틀린으로 카메라 켜기 (intent)



기능

1. 카메라 turn on 


architecture

- 카메라 버튼 클릭하면 카메라 turn on 



카메라를 turn on 하는법은 2가지가 있다.

1. intent

2. surface view 를 통해 preview 하는법


2번은 난이도가 조금 있기때문에 다음 시간에 하도록 하겠다.




intent 로 카메라 turn on을 할 때(target이 M 이 아닐때) 는 카메라 퍼미션이 따로 필요 없다.


android developer 홈페이지에 이렇게 나와 있다.

Note: if you app targets M and above and declares as using the Manifest.permission.CAMERA permission which is not granted, then attempting to use this action will result in a SecurityException.



아래처럼 코드 짜면 끝!




intent로 하는건 간단하기 때문에 다음시간에는 preview로 surfaceView를 사용해서 카메라 작동시키는법을 해보겠다!


이상한 점, 질문 아니면 더 효율적으로 짤 수 있는법 있으면 댓글에 남겨주세요 ~