일반적인 file chooser는 안드로이드에서 파일 열기 대화상자 만들기를 참고할 것
// Custom Mime Type을 Intent에 세팅해 주기 class GetContentWithMultiFilter:ActivityResultContracts.GetContent() { override fun createIntent(context: Context, input:String): Intent { val inputArray = input.split(";").toTypedArray() val myIntent = super.createIntent(context, "*/*") myIntent.putExtra(Intent.EXTRA_MIME_TYPES, inputArray) return myIntent } }
// File Chooser 함수 val pickPictureLauncher = rememberLauncherForActivityResult( GetContentWithMultiFilter()) { hwpUri -> if (hwpUri != null) { // Update the state with the Uri name = hwpUri.path.toString() val file: File = File(hwpUri.getPath()) //create path from uri val split = file.path.split(":".toRegex()).dropLastWhile { it.isEmpty() } .toTypedArray() //split the path. fname = split[1] //assign it to a string(your choice). } }
val inputString= "application/vnd.hancom.hwp;application/haansofthwp;application/x-hwp" // 한글 mime Button(onClick = { pickPictureLauncher.launch(inputString) } ) { Text(text = stringResource(R.string.fileopen)) }