Java Code Examples for android.net.Uri#getHost()
The following examples show how to use
android.net.Uri#getHost() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From shadowsocks-android-java with Apache License 2.0 | 6 votes |
boolean isValidUrl(String url) { try { if (url == null || url.isEmpty()) return false; if (url.startsWith("ss://")) {//file path return true; } else { //url Uri uri = Uri.parse(url); if (!"http".equals(uri.getScheme()) && !"https".equals(uri.getScheme())) return false; if (uri.getHost() == null) return false; } return true; } catch (Exception e) { return false; } }
Example 2
Source File: MessageListPanelEx.java From NIM_Android_UIKit with MIT License | 6 votes |
public void setChattingBackground(String uriString, int color) { if (uriString != null) { Uri uri = Uri.parse(uriString); if (uri.getScheme().equalsIgnoreCase("file") && uri.getPath() != null) { ivBackground.setImageBitmap(getBackground(uri.getPath())); } else if (uri.getScheme().equalsIgnoreCase("android.resource")) { List<String> paths = uri.getPathSegments(); if (paths == null || paths.size() != 2) { return; } String type = paths.get(0); String name = paths.get(1); String pkg = uri.getHost(); int resId = container.activity.getResources().getIdentifier(name, type, pkg); if (resId != 0) { ivBackground.setBackgroundResource(resId); } } } else if (color != 0) { ivBackground.setBackgroundColor(color); } }
Example 3
Source File: X5WebUtils.java From YCWebView with Apache License 2.0 | 6 votes |
/** * 判断是否为重定向url * @param url 原始链接 * @return True 为重定向链接 */ public static boolean shouldSkipUrl(@Nullable String url) { if (TextUtils.isEmpty(url)) { return true; } Uri uri = Uri.parse(url); final String host = uri.getHost(); //skip redirect if (!TextUtils.isEmpty(getKdtUnionUrl(uri))) { return true; } //skip 'about:blank' if (TextUtils.isEmpty(host)) { return true; } return false; }
Example 4
Source File: OpenGraphView.java From OpenGraphView with Apache License 2.0 | 6 votes |
private void setOpenGraphData(OGData data) { TextView url = (TextView) findViewById(R.id.og_url); TextView title = (TextView) findViewById(R.id.og_title); TextView description = (TextView) findViewById(R.id.og_description); if (data == null) { title.setText(mUrl); url.setText(""); description.setText(""); mRoundableImageView.setVisibility(GONE); return; } boolean isImageEmpty = TextUtils.isEmpty(data.getImage()); mRoundableImageView.setVisibility(isImageEmpty ? GONE : VISIBLE); if (TextUtils.isEmpty(data.getTitle()) && TextUtils.isEmpty(data.getDescription())) { title.setText(mUrl); description.setText(""); } else { title.setText(data.getTitle()); description.setText(data.getDescription()); } Uri uri = Uri.parse(mUrl); String host = uri.getHost(); url.setText(host == null ? mUrl : host); }
Example 5
Source File: ShadowsocksConfig.java From SmartZPN with GNU Lesser General Public License v3.0 | 6 votes |
public static ShadowsocksConfig parse(String proxyInfo) throws Exception { ShadowsocksConfig config = new ShadowsocksConfig(); Uri uri = Uri.parse(proxyInfo); if (uri.getPort() == -1) { String base64String = uri.getHost(); proxyInfo = "ss://" + new String(Base64.decode(base64String.getBytes("ASCII"), Base64.DEFAULT)); uri = Uri.parse(proxyInfo); } String userInfoString = uri.getUserInfo(); if (userInfoString != null) { String[] userStrings = userInfoString.split(":"); config.EncryptMethod = userStrings[0]; if (userStrings.length >= 2) { config.Password = userStrings[1]; } } config.ServerAddress = new InetSocketAddress(uri.getHost(), uri.getPort()); config.Encryptor = EncryptorFactory.createEncryptorByConfig(config); return config; }
Example 6
Source File: WebViewActivity.java From CloudReader with Apache License 2.0 | 6 votes |
/** * 作为三方浏览器打开 * Scheme: https * host: www.jianshu.com * path: /p/1cbaf784c29c * url = scheme + "://" + host + path; */ private void getDataFromBrowser(Intent intent) { Uri data = intent.getData(); if (data != null) { try { String scheme = data.getScheme(); String host = data.getHost(); String path = data.getPath(); // String text = "Scheme: " + scheme + "\n" + "host: " + host + "\n" + "path: " + path; // Log.e("data", text); String url = scheme + "://" + host + path; webView.loadUrl(url); } catch (Exception e) { e.printStackTrace(); } } }
Example 7
Source File: SRTPlayer.java From DeviceConnect-Android with MIT License | 6 votes |
/** * SRT プレイヤーを開始します. */ public synchronized void start() { if (mSRTClient != null) { return; } if (mUri == null) { throw new IllegalArgumentException("uri is not set."); } Uri uri = Uri.parse(mUri); if (!"srt".equals(uri.getScheme())) { throw new IllegalArgumentException("uri scheme is not srt."); } mPacketExtractor = new TsPacketExtractor(); mPacketExtractor.setCallback(mCallback); mPacketExtractor.start(); mSRTClient = new SRTClient(uri.getHost(), uri.getPort()); mSRTClient.setSocketOptions(mCustomSocketOptions); mSRTClient.setOnEventListener(mOnClientEventListener); mSRTClient.setStatsInterval(mStatsInterval); mSRTClient.setShowStats(mShowStats); mSRTClient.start(); }
Example 8
Source File: HttpHelper.java From Hentoid with Apache License 2.0 | 5 votes |
/** * Extract the domain from the given URI * * @param uriStr URI to parse, in String form * @return Domain of the URI; null if no domain found */ @Nullable private static String getDomainFromUri(@NonNull String uriStr) { Uri uri = Uri.parse(uriStr); String result = uri.getHost(); if (result != null && result.startsWith("www")) result = result.substring(3); return result; }
Example 9
Source File: ContextualSearchPolicy.java From 365browser with Apache License 2.0 | 5 votes |
/** * @return Whether the given URL is used for Accelerated Mobile Pages by Google. */ boolean isAmpUrl(String url) { Uri uri = Uri.parse(url); if (uri == null || uri.getHost() == null || uri.getPath() == null) return false; return uri.getHost().contains(DOMAIN_GOOGLE) && uri.getPath().startsWith(PATH_AMP); }
Example 10
Source File: Request.java From product-emm with Apache License 2.0 | 5 votes |
/** * @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; }
Example 11
Source File: IntentActivity.java From 4pdaClient-plus with Apache License 2.0 | 5 votes |
public static boolean tryShowClaim(Activity context, Handler handler, Uri uri) { if (uri.getHost() != null && !uri.getHost().contains("4pda.ru")) return false; if (!"report".equals(uri.getQueryParameter("act"))) return false; if (!TextUtils.isEmpty(uri.getQueryParameter("t")) && !TextUtils.isEmpty(uri.getQueryParameter("p"))) { org.softeg.slartus.forpdaplus.classes.Post.claim(context, handler, uri.getQueryParameter("t"), uri.getQueryParameter("p")); return true; } return false; }
Example 12
Source File: RedditURLParser.java From RedReader with GNU General Public License v3.0 | 5 votes |
private static boolean isRedditUri(Uri uri) { if (uri == null || uri.getHost() == null) return false; final String[] hostSegments = General.asciiLowercase(uri.getHost()).split("\\."); if (hostSegments.length < 2) return false; if (hostSegments[hostSegments.length - 1].equals("com") && hostSegments[hostSegments.length - 2].equals("reddit")) return true; if (hostSegments[hostSegments.length - 1].equals("it") && hostSegments[hostSegments.length - 2].equals("redd")) return true; return false; }
Example 13
Source File: HttpConnectConfig.java From SmartZPN with GNU Lesser General Public License v3.0 | 5 votes |
public static HttpConnectConfig parse(String proxyInfo) { HttpConnectConfig config = new HttpConnectConfig(); Uri uri = Uri.parse(proxyInfo); String userInfoString = uri.getUserInfo(); if (userInfoString != null) { String[] userStrings = userInfoString.split(":"); config.UserName = userStrings[0]; if (userStrings.length >= 2) { config.Password = userStrings[1]; } } config.ServerAddress = new InetSocketAddress(uri.getHost(), uri.getPort()); return config; }
Example 14
Source File: AndroidUtilities.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public static boolean shouldShowUrlInAlert(String url) { boolean hasLatin = false; boolean hasNonLatin = false; try { Uri uri = Uri.parse(url); url = uri.getHost(); for (int a = 0, N = url.length(); a < N; a++) { char ch = url.charAt(a); if (ch == '.' || ch == '-' || ch == '/' || ch == '+' || ch >= '0' && ch <= '9') { continue; } if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z') { hasLatin = true; } else { hasNonLatin = true; } if (hasLatin && hasNonLatin) { break; } } } catch (Exception e) { FileLog.e(e); } return hasLatin && hasNonLatin; }
Example 15
Source File: ImageResponseCache.java From kognitivo with Apache License 2.0 | 5 votes |
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; }
Example 16
Source File: WebViewJavaScriptBridgeBase.java From WebViewJavaScriptBridge with Apache License 2.0 | 4 votes |
boolean isQueueMessageURL(Uri url) { return !(null == url || null == url.getHost()) && url.getHost().equals(QUEUE_HAS_MESSAGE); }
Example 17
Source File: IntentActivity.java From 4pdaClient-plus with Apache License 2.0 | 4 votes |
public static boolean tryReputation(Activity context, Handler handler, Uri uri) { if (uri.getHost() != null && !uri.getHost().contains("4pda.ru")) return false; if (!"rep".equals(uri.getQueryParameter("act"))) return false; // история репутации if ("history".equals(uri.getQueryParameter("view")) && !TextUtils.isEmpty(uri.getQueryParameter("mid"))) { UserReputationFragment.showActivity( uri.getQueryParameter("mid"), "from".equals(uri.getQueryParameter("mode"))); return true; } // изменение репутации if (!TextUtils.isEmpty(uri.getQueryParameter("mid")) && !TextUtils.isEmpty(uri.getQueryParameter("view"))) { switch (uri.getQueryParameter("view")) { case "win_add": if (!TextUtils.isEmpty(uri.getQueryParameter("p"))) { ForumUser.startChangeRep(context, handler, uri.getQueryParameter("mid"), uri.getQueryParameter("mid"), uri.getQueryParameter("p"), "add", context.getString(R.string.increase_reputation)); } else { UserReputationFragment.plusRep(context, handler, uri.getQueryParameter("mid"), uri.getQueryParameter("mid")); } break; case "win_minus": if (!TextUtils.isEmpty(uri.getQueryParameter("p"))) { ForumUser.startChangeRep(context, handler, uri.getQueryParameter("mid"), uri.getQueryParameter("mid"), uri.getQueryParameter("p"), "minus", context.getString(R.string.decrease_reputation)); } else { UserReputationFragment.minusRep(context, handler, uri.getQueryParameter("mid"), uri.getQueryParameter("mid")); } break; default: return false; } return true; } return false; }
Example 18
Source File: ThemeFragment.java From 4pdaClient-plus with Apache License 2.0 | 4 votes |
private CharSequence prepareTopicUrl(CharSequence url) { final Uri uri = Uri.parse(url.toString()); return uri.getHost() == null ? uri.toString() : uri.getQuery(); }
Example 19
Source File: IntentActivity.java From 4pdaClient-plus with Apache License 2.0 | 4 votes |
public static boolean tryShowFile(final Activity activity, final Uri uri, final Boolean finish) { if (uri.getHost() != null && !(uri.getHost().toLowerCase().contains("4pda.ru") || uri.getHost().toLowerCase().contains("4pda.to") || uri.getHost().toLowerCase().contains("ggpht.com") || uri.getHost().toLowerCase().contains("googleusercontent.com") || uri.getHost().toLowerCase().contains("windowsphone.com") || uri.getHost().toLowerCase().contains("cs3-2.4pda.to") || uri.getHost().toLowerCase().contains("mzstatic.com") || uri.getHost().toLowerCase().contains("savepice.ru"))) return false; boolean isFile = PatternExtensions.compile("https?://4pda.ru/forum/dl/post/\\d+/[^\"]*") .matcher(uri.toString()).find() || PatternExtensions.compile("https?://st.4pda.ru/wp-content/uploads/[^\"]*") .matcher(uri.toString()).find() || ("attach".equals(uri.getQueryParameter("act")) && !TextUtils.isEmpty(uri.getQueryParameter("id"))); final Pattern imagePattern = PatternExtensions.compile("https?://.*?\\.(png|jpg|jpeg|gif)$"); if (isFile) { if (!Client.getInstance().getLogined() && !Client.getInstance().hasLoginCookies()) { Client.getInstance().showLoginForm(activity); } else { if (imagePattern.matcher(uri.toString()).find()) { // showImage(activity, uri.toString()); showImage(activity, uri.toString()); if (finish) activity.finish(); } else downloadFileStart(activity, uri.toString(), finish); } return true; } if (imagePattern.matcher(uri.toString()).find() || (uri.getHost().toLowerCase().contains("ggpht.com") || uri.getHost().toLowerCase().contains("googleusercontent.com") || uri.getHost().toLowerCase().contains("windowsphone.com") || uri.getHost().toLowerCase().contains("savepice.ru"))) { // showImage(activity, uri.toString()); showImage(activity, uri.toString()); if (finish) activity.finish(); return true; } return false; }
Example 20
Source File: RexxarWebViewClient.java From rexxar-android with MIT License | 4 votes |
/** * @param requestUrl * @return */ private boolean shouldIntercept(String requestUrl) { if (TextUtils.isEmpty(requestUrl)) { return false; } // file协议需要替换,用于html if (requestUrl.startsWith(Constants.FILE_AUTHORITY)) { return true; } // rexxar container api,需要拦截 if (requestUrl.startsWith(Constants.CONTAINER_API_BASE)) { return true; } // 非合法uri,不拦截 Uri uri = null; try { uri = Uri.parse(requestUrl); } catch (Exception e) { e.printStackTrace(); } if (null == uri) { return false; } // 非合法host,不拦截 String host = uri.getHost(); if (TextUtils.isEmpty(host)) { return false; } // 不能拦截的uri,不拦截 Pattern pattern; Matcher matcher; for (String interceptHostItem : ResourceProxy.getInstance().getProxyHosts()) { pattern = Pattern.compile(interceptHostItem); matcher = pattern.matcher(host); if (matcher.find()) { return true; } } return false; }