Last active
March 29, 2016 01:00
-
-
Save hkurokawa/1fdda8ee053940fe2816 to your computer and use it in GitHub Desktop.
A utility method to encode only the path segments of the given URL on Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.net.Uri; | |
| import android.util.Pair; | |
| import java.util.List; | |
| public final class UrlUtil { | |
| static String encodePathSegments(String url) { | |
| final Uri uri = Uri.parse(url); | |
| final List<String> pathSegments = uri.getPathSegments(); | |
| final Uri.Builder builder = uri.buildUpon().path(""); | |
| for (String s : pathSegments) { | |
| builder.appendEncodedPath(Uri.encode(s)); | |
| } | |
| return builder.build().toString(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment