사용자 도구

사이트 도구


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

문서의 이전 판입니다!


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_에서_hwp_파일만_보여주는_대화상자_만들기.1691078420.txt.gz · 마지막으로 수정됨: 2023/08/04 01:00 (바깥 편집)