- // `@SuppressLint("InflateParams")` removes the warning about using null as the parent view group when inflating the alert dialog.
- @SuppressLint("InflateParams")
+ // Define the browse activity result launcher.
+ private val browseActivityResultLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { fileUri: Uri? ->
+ // Only do something if the user didn't press back from the file picker.
+ if (fileUri != null) {
+ // Get the file name string from the URI.
+ val fileNameString = fileUri.toString()
+
+ // Set the file name text.
+ fileNameEditText.setText(fileNameString)
+
+ // Move the cursor to the end of the file name edit text.
+ fileNameEditText.setSelection(fileNameString.length)
+ }
+ }
+