사용자 도구

사이트 도구


android:android_에서_hwp_파일만_보여주는_대화상자_만들기
android 에서 hwp 파일만 보여주는 대화상자 만들기

일반적인 file chooser는 안드로이드에서 파일 열기 대화상자 만들기를 참고할 것

1. Intent에 Mime을 구성해 주는 함수 만들기

// 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
    }
}

2. 파일 열기 대화상자 함수 만들기

// 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).
 
    }
}

3. 불러오기

val inputString= "application/vnd.hancom.hwp;application/haansofthwp;application/x-hwp"  // 한글 mime 
 
Button(onClick = { pickPictureLauncher.launch(inputString)  } ) {
         Text(text = stringResource(R.string.fileopen))
}
로그인하면 댓글을 남길 수 있습니다.

android/android_에서_hwp_파일만_보여주는_대화상자_만들기.txt · 마지막으로 수정됨: 2023/08/04 01:04 저자 이거니맨