반응형
ACTION_PICK으로 선택이 아니라 보기 상태로 갤러리를 진입하는 방법입니다.
val intent = Intent(Intent.ACTION_VIEW)
intent.type = "image/*"
startActivity(intent)
초기에는 위 코드로 단순하게 진입할 수 있었으나 매 진입 시마다 "지원되지 않는 파일 형식입니다"라는 Toast가 팝업 되었습니다.
보통 ACTION_VIEW는 특정 파일을 열도록 되어 있기 때문에 type에 지정한 경로로는 제대로 된 파일 형식을 열어주지 못하고 image 폴더 전체를 보여주게 됩니다.
이러한 오류 현상을 기반으로 갤러리 앱을 열지 않으려면 갤러리 앱 자체의 package name을 찾아 intent 처리해 주면 되겠습니다.
val galleryIntent = activity.packageManager.getLaunchIntentForPackage("com.sec.android.gallery3d")
if (galleryIntent != null) {
startActivity(galleryIntent)
} else {
val intent = Intent(Intent.ACTION_VIEW)
intent.type = "image/*"
startActivity(intent)
}
참고로 픽셀 기기의 경우에는 다음과 같은 패키지명을 가지고 있습니다.
com.google.android.apps.photo
참고)
https://stackoverflow.com/questions/69729683/how-to-start-gallery-app-from-an-android-app
How to start gallery app from an android app?
I am trying to open the gallery app from my android application. I want to just open the gallery app and not other apps with like fotos. I have tried intent.setAction(Intent.ACTION_GET_CONTENT); in...
stackoverflow.com
반응형