我想在网址下方转换
https://sdcude.pdakmddda.at/sdtddio/img/thumbnails/original/ÖffnungszeitenTest-638.jpg
至
https://sdcude.pdakmdda.at/sdtddio/img/thumbnails/original/%C3%96ffnungszeiten%20Test-638.jpg
Logcat01-29 16:40:36.195: W/System.err(15131): java.net.MalformedURLException: Protocol not found: https%3A%2F%2Fsdcdre.pdadkdedia.at%2Fdddio%2Fimg%2Fthumbnails%2Foriginal%2F%C3%96ffnungszeiten+Test-638.jpg
01-29 16:40:36.218: W/System.err(15131): at java.net.URL.<init>(URL.java:178)
01-29 16:40:36.218: W/System.err(15131): at java.net.URL.<init>(URL.java:127)
01-29 16:40:36.218: W/System.err(15131): at com.peak.media.HomeActivityNewViewPager$FirstDownloadFileFromURL.doInBackground(HomeActivityNewViewPager.java:2478)
01-29 16:40:36.218: W/System.err(15131): at com.peak.media.HomeActivityNewViewPager$FirstDownloadFileFromURL.doInBackground(HomeActivityNewViewPager.java:1)
01-29 16:40:36.218: W/System.err(15131): at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-29 16:40:36.218: W/System.err(15131): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-29 16:40:36.218: W/System.err(15131): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-29 16:40:36.218: W/System.err(15131): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
01-29 16:40:36.218: W/System.err(15131): at java.lang.Thread.run(Thread.java:856)
编码后我需要以上结果。我不知道上面的网址使用哪种编码。
String newurl=URLEncoder.encode(url,"UTF-8");
转换后,我使用UTF-8到达了以下网址
[https%3A%2F%2Fsddde.psdfma.co%2Fstudio%2Fimg%2Fthumbnails%2Foriginal%2F%C3%96ffnungszeiten + Test-638.jpg] [2]
最佳答案
只是因为网址中出现空格Ravi Thapliyal答案不正确,否则是正确的
下面对我来说工作
String ALLOWED_URI_CHARS = "@#&=*+-_ .,:!?()/~'%";
String spaceurl = Uri.encode(f_url[0], ALLOWED_URI_CHARS);
String newurl=spaceurl.replaceAll(" ", "%20");