Preethi Preethi - 2 months ago 10
Java Question

get specific data from URL in android/java?

I have a url like this

https://example.com%3A443:443/www/36d8e8c94aae45048ba9f92f8e62c7b2/file/content?path=%2Fmnt%2Fsdcard%2Fvideo%2Fsample_mpeg4.mp4&yyy=9a7491a1f5664336b5c6bf431f42852c3749ed54722736ec748746858a710c44

I need to get the path of file as /mnt/sdcard/video from the URL . How do i do that ?
I used URL decoder to remove the spaces but i am confused on getting the path of the file .
Thanks for all your help.

Answer

Use Uri.getQueryParameter().

import android.net.Uri;

Uri uri = Uri.parse("https://example.com%3A443:443/www/36d8e8c94aae45048ba9f92f8e62c7b2/file/content?path=%2Fmnt%2Fsdcard%2Fvideo%2Fsample_mpeg4.mp4&yyy=9a7491a1f5664336b5c6bf431f42852c3749ed54722736ec748746858a710c44");
String pathParam = uri.getQueryParameter("path");
Comments