Kivy 시작하기 14.06 (모바일 앱 만들기 6)
사용 버전: Python 3.7.6, Kivy 1.11.1
사용 프로그램: Atom 1.43.0 x64
운영체제: 페도라 31 Workstation x64, Android 9 Pie
14.05 글에서는 저장한 이미지가 휴대폰에서 보이지 않는 문제가 있었습니다.
https://youtu.be/wx1kHmHYnJg
오늘은 이것을 해결하도록 하겠습니다.
MediaScannerConnection API를 사용합니다.

기본 구조는 다음과 같습니다.

우선 MediaScannerConnection을 autoclass로 연결합니다.

MediaScannerConnection Class를 만들려면 첫 번째 인자 Context와 두 번째 인자 MediaScannerConnectionClient가 필요합니다.



MediaScannerConnection이 휴대폰과 연결되면 자동으로 MediaScannerConnectionClient의 onMediaScannerConnected()와 onScanCompleted()가 실행되기 때문에 단순한 autoclass로 불러올 수 없습니다.
따라서 위의 Java 클래스를 Python에서 재정의를 해줍니다.

터미널을 키고, Sdk가 설치되어 있는 위치로 이동합니다.
cd $HOME/Android/Sdk/platforms/android-29

javap -s -classpath android.jar android.media.MediaScannerConnection.MediaScannerConnectionClient

위의 descriptor가 java_method로 Java 함수를 재정의할 때 필요합니다.
PythonMediaClient라는 이름으로 재정의 해줍니다.

onMediaScannerConnected() 함수는 미디어 스캐너가 연결되었을 때, 실행됩니다.
연결이 되었다면, scanFile을 실행하여, scan을 실행합니다.

그리고 경로를 변경하게 될 시, 전역변수 Image_path가 변환되지만, 다른 class에는 반영이 안되므로, 반영시키는 class를 하나 더 만듭니다.

Client와 Connection을 할당합니다.

connect(), disconnect() methods를 사용합니다.


다시 빌드를 해봅시다.

짜잔, 완성입니다.
https://youtu.be/QeB6Zf3-pII
끝.
앱:
https://play.google.com/store/apps/details?id=starlight.jaehwa.one
코드:
https://github.com/shwoghk14/Kivy_for_Starter
사용 프로그램: Atom 1.43.0 x64
운영체제: 페도라 31 Workstation x64, Android 9 Pie
기획: URL 소스 자료를 내 휴대폰에 저장하는 앱.
14.05 글에서는 저장한 이미지가 휴대폰에서 보이지 않는 문제가 있었습니다.
https://youtu.be/wx1kHmHYnJg
오늘은 이것을 해결하도록 하겠습니다.
MediaScannerConnection API를 사용합니다.

기본 구조는 다음과 같습니다.

우선 MediaScannerConnection을 autoclass로 연결합니다.

MediaScannerConnection Class를 만들려면 첫 번째 인자 Context와 두 번째 인자 MediaScannerConnectionClient가 필요합니다.



MediaScannerConnection이 휴대폰과 연결되면 자동으로 MediaScannerConnectionClient의 onMediaScannerConnected()와 onScanCompleted()가 실행되기 때문에 단순한 autoclass로 불러올 수 없습니다.
따라서 위의 Java 클래스를 Python에서 재정의를 해줍니다.

터미널을 키고, Sdk가 설치되어 있는 위치로 이동합니다.
cd $HOME/Android/Sdk/platforms/android-29

javap -s -classpath android.jar android.media.MediaScannerConnection.MediaScannerConnectionClient

위의 descriptor가 java_method로 Java 함수를 재정의할 때 필요합니다.
PythonMediaClient라는 이름으로 재정의 해줍니다.

onMediaScannerConnected() 함수는 미디어 스캐너가 연결되었을 때, 실행됩니다.
연결이 되었다면, scanFile을 실행하여, scan을 실행합니다.

그리고 경로를 변경하게 될 시, 전역변수 Image_path가 변환되지만, 다른 class에는 반영이 안되므로, 반영시키는 class를 하나 더 만듭니다.

Client와 Connection을 할당합니다.

connect(), disconnect() methods를 사용합니다.


다시 빌드를 해봅시다.

짜잔, 완성입니다.
https://youtu.be/QeB6Zf3-pII
끝.
앱:
https://play.google.com/store/apps/details?id=starlight.jaehwa.one
코드:
https://github.com/shwoghk14/Kivy_for_Starter
카테고리: BlackSmith, Kivy
댓글
댓글 쓰기
궁금한 점은 댓글 달아주세요.
Comment if you have any questions.