Open File choose in Android app using Kotlin

后端 未结 2 2132
北恋
北恋 2021-02-09 13:44

Task: Upload an image which user can choose from device.

How to open File CHooser window on button press in Android app using Kotlin?

2条回答
  •  天命终不由人
    2021-02-09 14:16

    I am using it in a pdf reader inside of a Fragment. Adding my code: but I do not know yet how I define the correct directory to choose my file.

        val selectedFile = data?.data //The uri with the location of the file 

    pdfView.fromUri(selectedFile).load() // Show the selected file //Fragment view override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val intent = Intent() .setType("*/*") .setAction(Intent.ACTION_GET_CONTENT) startActivityForResult(Intent.createChooser(intent, "Select a file"), 111) return inflater.inflate(R.layout.fragment_sat,container,false) }

提交回复
热议问题