본문 바로가기
개발일지/Android Studio

[Android Studio] TedPermission

by 최호희 2024. 8. 28.

들어가며,

졸업작품 프로젝트를 진행하는데 Android Studio를 사용하는 파트가 주어졌다

사용할 기술은 'OCR' 기능으로, 휴대폰 카메라로 카드를 촬영할 시 카드번호를 인식하여 이를 Springboot 서버로 넘겨주는 부분이다.

카메라 촬영 시 권한이 필요하다

예시)

 


TedPermission은 라이브러리이다

권한 허용을 쉽게해주는 라이브러리이다 안드로이드에서는 특정 동작을 위하여 권한이 필요하다.

일반권한은 개인정보를 요청하지 않는 권한으로 앱 설치시 권한을 요청하며, 대표적으로 인터넷 접근 권한, 와이파이 접근 권한, 블루투스 접근 권한 등이 있다.

위험권한은 개인정보를 요청하는 권한으로 그 기능이 동작할때 권한을 요청하며, 대표적으로 카메라, 위치, 갤러리, 주소록 권한 등이 있다

 

카메라 기능 사용


권한 추가

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

 

 

 

 

activity_main 레이아웃 구성하기


1. ImageView 배치하기

이 ImageView는 나중에 빌드해서 촬영했을 때, 이미지가 이 화면에 뜰것입니다.

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <ImageView
            android:id="@+id/iv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </LinearLayout>

 

 

2. Button 배치하기

이 버튼은 나중에 눌렀을 때 카메라로 이동할 것입니다.

    <LinearLayout
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/btn_capture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="촬영" />

    </LinearLayout>