Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] java – how to get file path from intent data uri

Posted on November 14, 2022

Solution 1 :

You can simply replace the /external_files with the external directory.

 val intentPath = activity?.intent!!.data!!.path!!

 val absolutePath = Environment.getExternalStorageDirectory().toString() + intentPath.substringAfter("/external_files") 

 e.g

 println("Intent Path : ${intentPath}")
 // Intent Path : external_files/KannadaGeeta/05CHAPTER2.mp3

 println("Absolute Path : ${absolutePath}")
 // Absolute Path : /storage/emulated/0/KannadaGeeta/05CHAPTER2.mp3

Problem :

I’m using intent to select a video,

fun openVideo(view: View) {
        val intent = Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI)
        intent.type = "video/*"
        startActivityForResult(
            Intent.createChooser(intent, "Select Video"),
            REQUEST_TAKE_GALLERY_VIDEO
        )
}

then i’m getting uri and path

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == REQUEST_TAKE_GALLERY_VIDEO && data != null) {

            val videPath = data.data?.path 
            val selectedVideoUri: Uri? = data!!.data.toString()
        }
    }

output

videPath:
/external_files/KannadaGeeta/05CHAPTER2.mp3

selectedVideoUri :
content://com.mi.android.globalFileexplorer.myprovider/external_files/KannadaGeeta/05CHAPTER2.mp3

but I need path like below to check whether file exist or not

/storage/emulated/0/KannadaGeeta/13CHAPTER12.mp3

Look, by working on strings I can achieve what I want. But I’m looking for a proper way to get the video path.

Can anyone help me on this.

Edit:

i tried this which is giving false

File(selectedVideoUri).exists()

Comments

Comment posted by blackapps

You do not have to check if the file exists. If the file did not exist the user could not have picked it.

Comment posted by blackapps

You should save

Comment posted by blackapps

You realise that

Comment posted by blackapps

I do not understand what you mean with ‘i do not want to work on strings’. A path is a string too isnt it?

Comment posted by blackapps

You do not have to format anything. And you should not try to convert an uri -a nice content scheme- to a file system path. As a professional you should use the obtained uri directly. What is the reason you want a path? That uri is all you need.

READ  [ANSWERED] android - MainActivity RecyclerView and Room Database crash - Java
Powered by Inline Related Posts

Comment posted by Vikas Acharya

I have already mentioned in my question “Look, by working on strings I can achieve what I want. But I’m looking for a proper way to get the video path.”

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress