Uri data = getIntent().getData(); String scheme = data.getScheme(); // "http" String host = data.getHost(); // "twitter.com" List<String> params = data.getPathSegments(); String first = params.get(0); // "status" String second = params.get(1); // "1234"
private static boolean isCDNURL(Uri uri) { if (uri != null) { String uriHost = uri.getHost(); if (uriHost.endsWith("fbcdn.net")) { return true; } if (uriHost.startsWith("fbcdn") && uriHost.endsWith("akamaihd.net")) { return true; } } return false; }
@Override public String getSource() { return TextUtils.isEmpty(url) ? null : Uri.parse(url).getHost(); }
/** * @return The hashcode of the URL's host component, or 0 if there is none. */ private static int findDefaultTrafficStatsTag(String url) { if (!TextUtils.isEmpty(url)) { Uri uri = Uri.parse(url); if (uri != null) { String host = uri.getHost(); if (host != null) { return host.hashCode(); } } } return 0; }
/** * @return The hashcode of the URL's host component, or 0 if there is none. */ private static int findDefaultTrafficStatsTag(String url) { if (!TextUtils.isEmpty(url)) { Uri uri = Uri.parse(url); if (uri != null) { String host = uri.getHost(); if (host != null) { return host.hashCode(); } } } return 0; }
/** * @return The hashcode of the URL's host component, or 0 if there is none. */ private static int findDefaultTrafficStatsTag(String url) { if (!TextUtils.isEmpty(url)) { Uri uri = Uri.parse(url); if (uri != null) { String host = uri.getHost(); if (host != null) { return host.hashCode(); } } } return 0; }
private static String getMediaUrlKey(Uri url) { String host = url.getHost(); return !Utility.isNullOrEmpty(host) && FACEBOOK_DOMAIN.matcher(host).matches() ? ShareConstants.MEDIA_URI : ShareConstants.IMAGE_URL; }
public void setUrl(String url) { this.url = url; Uri uri = Uri.parse(url); host = uri.getHost(); path = uri.getPath() + ((uri.getQuery() != null) ? "?" + uri.getQuery() : ""); scheme = uri.getScheme(); }
/** * Returns whether it may be possible to load the given URIs based on the network security * policy's cleartext traffic permissions. * * @param uris A list of URIs that will be loaded. * @return Whether it may be possible to load the given URIs. */ @TargetApi(24) public static boolean checkCleartextTrafficPermitted(Uri... uris) { if (Util.SDK_INT < 24) { // We assume cleartext traffic is permitted. return true; } for (Uri uri : uris) { if ("http".equals(uri.getScheme()) && !NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted(uri.getHost())) { // The security policy prevents cleartext traffic. return false; } } return true; }
public UriAssert hasHost(String host) { isNotNull(); String actualHost = actual.getHost(); assertThat(actualHost) .overridingErrorMessage("Expected host <%s> but was <%s>.", host, actualHost) .isEqualTo(host); return this; }
@Override public String getSource() { return TextUtils.isEmpty(getUrl()) ? null : Uri.parse(getUrl()).getHost(); }
if (!HackerNewsClient.BASE_WEB_URL.contains(Uri.parse(url).getHost())) { if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent);
@Override public long open(DataSpec dataSpec) throws UdpDataSourceException { uri = dataSpec.uri; String host = uri.getHost(); int port = uri.getPort(); transferInitializing(dataSpec); try { address = InetAddress.getByName(host); socketAddress = new InetSocketAddress(address, port); if (address.isMulticastAddress()) { multicastSocket = new MulticastSocket(socketAddress); multicastSocket.joinGroup(address); socket = multicastSocket; } else { socket = new DatagramSocket(socketAddress); } } catch (IOException e) { throw new UdpDataSourceException(e); } try { socket.setSoTimeout(socketTimeoutMillis); } catch (SocketException e) { throw new UdpDataSourceException(e); } opened = true; transferStarted(dataSpec); return C.LENGTH_UNSET; }
if (!HOST_DEFAULT.equals(uri.getHost())) { return null;
LogUtils.i(TAG, "getAuthority:" + fileUri.getAuthority() + " getHost:" + fileUri.getHost() + " getPath:" + fileUri.getPath() + " getScheme:" + fileUri.getScheme() + " query:" + fileUri.getQuery()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, fileUri)) { if (isExternalStorageDocument(fileUri)) {
@Test public void shouldParseUris() throws Exception { Uri testUri = Uri.parse("http://someplace.com:8080/a/path?param=value&another_param=another_value#top"); assertThat(testUri.getQuery()).isEqualTo("param=value&another_param=another_value"); assertThat(testUri.getPort()).isEqualTo(8080); assertThat(testUri.getAuthority()).isEqualTo("someplace.com:8080"); assertThat(testUri.getHost()).isEqualTo("someplace.com"); assertThat(testUri.getFragment()).isEqualTo("top"); assertThat(testUri.getPath()).isEqualTo("/a/path"); assertThat(testUri.getScheme()).isEqualTo("http"); }
static private Intent getIntentForURI(Uri data) { if (HOST_GISTS.equals(data.getHost())) { Gist gist = GistUriMatcher.getGist(data); if (gist != null) { return GistsViewActivity.createIntent(gist); } } else if (HOST_DEFAULT.equals(data.getHost())) { CommitMatch commit = CommitUriMatcher.getCommit(data); if (commit != null) { return CommitViewActivity.createIntent(commit.getRepository(), commit.getCommit()); } Issue issue = IssueUriMatcher.getIssue(data); if (issue != null) { return IssuesViewActivity.createIntent(issue, issue.repository()); } Repository repository = RepositoryUriMatcher.getRepository(data); if (repository != null) { return RepositoryViewActivity.createIntent(repository); } User user = UserUriMatcher.getUser(data); if (user != null) { return UserViewActivity.createIntent(user); } } return null; }