Java Code Examples for android.net.Uri#getPort()
The following examples show how to use
android.net.Uri#getPort() .
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: Sentry.java From Sentry-Android with MIT License | 6 votes |
public static void init(Context context, String dsn, boolean setupUncaughtExceptionHandler) { final Sentry sentry = Sentry.getInstance(); sentry.context = context.getApplicationContext(); Uri uri = Uri.parse(dsn); String port = ""; if (uri.getPort() >= 0) { port = ":" + uri.getPort(); } sentry.baseUrl = uri.getScheme() + "://" + uri.getHost() + port; sentry.dsn = uri; sentry.appInfo = AppInfo.Read(sentry.context); sentry.verifySsl = getVerifySsl(dsn); sentry.contexts = readContexts(sentry.context, sentry.appInfo); sentry.executor = fixedQueueDiscardingExecutor(MAX_QUEUE_LENGTH); if (setupUncaughtExceptionHandler) { sentry.setupUncaughtExceptionHandler(); } }
Example 2
Source File: ShadowsocksConfig.java From SmartProxy with GNU 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 3
Source File: Socket.java From talk-android with MIT License | 6 votes |
private static Options fromURI(Uri uri, Options opts) { if (opts == null) { opts = new Options(); } opts.host = uri.getHost(); opts.secure = "https".equals(uri.getScheme()) || "wss".equals(uri.getScheme()); opts.port = uri.getPort(); String query = uri.getQuery(); if (query != null) { opts.query = query; } return opts; }
Example 4
Source File: AndroidProtocolHandler.java From OsmGo with MIT License | 6 votes |
public InputStream openContentUrl(Uri uri) throws IOException { Integer port = uri.getPort(); String baseUrl = uri.getScheme() + "://" + uri.getHost(); if (port != -1) { baseUrl += ":" + port; } String realPath = uri.toString().replace(baseUrl + Bridge.CAPACITOR_CONTENT_START, "content:/"); InputStream stream = null; try { stream = context.getContentResolver().openInputStream(Uri.parse(realPath)); } catch (SecurityException e) { Log.e(LogUtils.getCoreTag(), "Unable to open content URL: " + uri, e); } return stream; }
Example 5
Source File: HttpClient.java From Dashchan with Apache License 2.0 | 6 votes |
URL encodeUri(Uri uri) throws MalformedURLException { StringBuilder uriStringBuilder = new StringBuilder(); uriStringBuilder.append(uri.getScheme()).append("://"); String host = IDN.toASCII(uri.getHost()); uriStringBuilder.append(host); int port = uri.getPort(); if (port != -1) { uriStringBuilder.append(':').append(port); } String path = uri.getEncodedPath(); if (!StringUtils.isEmpty(path)) { encodeUriAppend(uriStringBuilder, path); } String query = uri.getEncodedQuery(); if (!StringUtils.isEmpty(query)) { uriStringBuilder.append('?'); encodeUriAppend(uriStringBuilder, query); } return new URL(uriStringBuilder.toString()); }
Example 6
Source File: AsyncHttpRequest.java From MediaSDK with Apache License 2.0 | 5 votes |
public static void setDefaultHeaders(Headers ret, Uri uri) { if (uri != null) { String host = uri.getHost(); if (uri.getPort() != -1) host = host + ":" + uri.getPort(); if (host != null) ret.set("Host", host); } ret.set("User-Agent", getDefaultUserAgent()); ret.set("Accept-Encoding", "gzip, deflate"); ret.set("Connection", "keep-alive"); ret.set("Accept", HEADER_ACCEPT_ALL); }
Example 7
Source File: HttpConnectConfig.java From shadowsocks-android-java with Apache License 2.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 8
Source File: BUtility.java From appcan-android with GNU Lesser General Public License v3.0 | 5 votes |
/** * 得到去掉参数的路径 * * @return */ public static String makeSpecUrl(String inBaseUrl) { Uri path = Uri.parse(inBaseUrl); String port = path.getPort() != -1 ? ":" + String.valueOf(path.getPort()) : ""; return path.getScheme() + "://" + path.getHost() + port + path.getPath(); }
Example 9
Source File: WebsitePreference.java From delion with Apache License 2.0 | 5 votes |
/** * Returns the url of the site to fetch a favicon for. */ private String faviconUrl() { String origin = mSite.getAddress().getOrigin(); if (origin == null) { return "http://" + mSite.getAddress().getHost(); } Uri uri = Uri.parse(origin); if (uri.getPort() != -1) { // Remove the port. uri = uri.buildUpon().authority(uri.getHost()).build(); } return uri.toString(); }
Example 10
Source File: TestUtils.java From okta-sdk-appauth-android with Apache License 2.0 | 5 votes |
public static String getBaseUrl(Uri uri) { String baseUrl = uri.getScheme()+"://"+uri.getHost(); if(uri.getPort() != -1) { baseUrl = baseUrl + ":"+uri.getPort(); } return baseUrl; }
Example 11
Source File: HttpConnectConfig.java From SmartProxy with GNU 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 12
Source File: LoginActivity.java From tapchat-android with Apache License 2.0 | 5 votes |
private Uri getBaseUri() { String hostname = mServerEditText.getText().toString(); Uri uri = Uri.parse(String.format("https://%s/chat/", hostname)); if (uri.getPort() <= 0) { uri = Uri.parse(String.format("https://%s:%s/chat/", hostname, DEFAULT_PORT)); } return uri; }
Example 13
Source File: PortFilter.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean matches(IntentFirewall ifw, ComponentName resolvedComponent, Intent intent, int callerUid, int callerPid, String resolvedType, int receivingUid) { int port = -1; Uri uri = intent.getData(); if (uri != null) { port = uri.getPort(); } return port != -1 && (mLowerBound == NO_BOUND || mLowerBound <= port) && (mUpperBound == NO_BOUND || mUpperBound >= port); }
Example 14
Source File: AsyncSocketMiddleware.java From MediaSDK with Apache License 2.0 | 5 votes |
public int getSchemePort(Uri uri) { if (uri.getScheme() == null || !uri.getScheme().equals(scheme)) return -1; if (uri.getPort() == -1) { return port; } else { return uri.getPort(); } }
Example 15
Source File: SchemeActivity.java From YCVideoPlayer with Apache License 2.0 | 4 votes |
private void getDataFromBrower() { Uri uri = getIntent().getData(); if (uri != null) { // 完整的url信息 String url = uri.toString(); LogUtils.i("SchemeActivity---" + "url: " + uri); // scheme部分 String scheme = uri.getScheme(); LogUtils.i("SchemeActivity---" + "scheme: " + scheme); // host部分 String host = uri.getHost(); LogUtils.i("SchemeActivity---" + "host: " + host); //port部分 int port = uri.getPort(); LogUtils.i("SchemeActivity---" + "host: " + port); // 访问路劲 String path = uri.getPath(); LogUtils.i("SchemeActivity---" + "path: " + path); // 获取参数 List<String> pathSegments = uri.getPathSegments(); LogUtils.i("SchemeActivity---" + "pathSegments: " + pathSegments.size()); // Query部分 String query = uri.getQuery(); LogUtils.i("SchemeActivity---" + "query: " + query); //获取指定参数值 String page = uri.getQueryParameter("page"); LogUtils.i("SchemeActivity---" + "page: " + page); //获取指定参数值,该方法获取值一直是空 //String level = uri.getQueryParameter("level"); ///Log.e( "UrlUtils","level: " + level); //String level = getValueByName(url, "level"); //LoggerUtils.i( "SchemeActivity---","level: " + level); if (page==null || page.length()==0) { finish(); return; } switch (page) { case "main": //唤起客户端,进入首页 //https://yc.com?page=main Intent intent1 = new Intent(this, MainActivity.class); readGoActivity(intent1, this); break; case "full": //唤起客户端,进入A页面 //https://yc.com?page=full Intent intent2 = new Intent(this, TestFullActivity.class); readGoActivity(intent2, this); break; case "list": //唤起客户端,进入B页面,携带参数 //https://yc.com?page=list&id=520 Intent intent3 = new Intent(this, TestListActivity.class); String id = getValueByName(url, "id"); intent3.putExtra("id",id); readGoActivity(intent3, this); break; case "small": //唤起客户端,进入C页面 Intent intent4 = new Intent(this, TestRecyclerActivity.class); readGoActivity(intent4, this); break; default: Intent intent = new Intent(this, MainActivity.class); readGoActivity(intent, this); break; } } }
Example 16
Source File: Utilities.java From firebase-android-sdk with Apache License 2.0 | 4 votes |
public static ParsedUrl parseUrl( @NonNull String url, @Nullable EmulatedServiceSettings emulatorSettings) throws DatabaseException { try { Uri uri = Uri.parse(url); String scheme = uri.getScheme(); if (scheme == null) { throw new IllegalArgumentException("Database URL does not specify a URL scheme"); } String host = uri.getHost(); if (host == null) { throw new IllegalArgumentException("Database URL does not specify a valid host"); } String namespace = uri.getQueryParameter("ns"); if (namespace == null) { String[] parts = host.split("\\.", -1); namespace = parts[0].toLowerCase(); } RepoInfo repoInfo = new RepoInfo(); if (emulatorSettings != null) { repoInfo.host = emulatorSettings.getHost() + ":" + emulatorSettings.getPort(); repoInfo.secure = false; } else { repoInfo.host = host.toLowerCase(); int port = uri.getPort(); if (port != -1) { repoInfo.secure = scheme.equals("https") || scheme.equals("wss"); repoInfo.host += ":" + port; } else { repoInfo.secure = true; } } repoInfo.internalHost = repoInfo.host; repoInfo.namespace = namespace; String originalPathString = extractPathString(url); // URLEncoding a space turns it into a '+', which is different // from our expected behavior. Do a manual replace to fix it. originalPathString = originalPathString.replace("+", " "); Validation.validateRootPathString(originalPathString); ParsedUrl parsedUrl = new ParsedUrl(); parsedUrl.path = new Path(originalPathString); parsedUrl.repoInfo = repoInfo; return parsedUrl; } catch (Exception e) { throw new DatabaseException("Invalid Firebase Database url specified: " + url, e); } }
Example 17
Source File: OAuthDialogFragment.java From mirror with Apache License 2.0 | 4 votes |
static boolean isRedirectUriFound(String uri, String redirectUri) { Uri u; Uri r; try { u = Uri.parse(uri); r = Uri.parse(redirectUri); } catch (NullPointerException e) { return false; } if (u == null || r == null) { return false; } boolean rOpaque = r.isOpaque(); boolean uOpaque = u.isOpaque(); if (rOpaque != uOpaque) { return false; } if (rOpaque) { return TextUtils.equals(uri, redirectUri); } if (!TextUtils.equals(r.getScheme(), u.getScheme())) { return false; } if (!TextUtils.equals(r.getAuthority(), u.getAuthority())) { return false; } if (r.getPort() != u.getPort()) { return false; } if (!TextUtils.isEmpty(r.getPath()) && !TextUtils.equals(r.getPath(), u.getPath())) { return false; } Set<String> paramKeys = CompatUri.getQueryParameterNames(r); for (String key : paramKeys) { if (!TextUtils.equals(r.getQueryParameter(key), u.getQueryParameter(key))) { return false; } } String frag = r.getFragment(); return !(!TextUtils.isEmpty(frag) && !TextUtils.equals(frag, u.getFragment())); }
Example 18
Source File: SwapWorkflowActivity.java From fdroidclient with GNU General Public License v3.0 | 4 votes |
private void setUpFromWifi() { String scheme = Preferences.get().isLocalRepoHttpsEnabled() ? "https://" : "http://"; // the fingerprint is not useful on the button label String buttonLabel = scheme + FDroidApp.ipAddressString + ":" + FDroidApp.port; TextView ipAddressView = container.findViewById(R.id.device_ip_address); if (ipAddressView != null) { ipAddressView.setText(buttonLabel); } String qrUriString = null; switch (currentView.getLayoutResId()) { case R.layout.swap_join_wifi: setUpJoinWifi(); return; case R.layout.swap_send_fdroid: qrUriString = buttonLabel; break; case R.layout.swap_wifi_qr: Uri sharingUri = Utils.getSharingUri(FDroidApp.repo); StringBuilder qrUrlBuilder = new StringBuilder(scheme); qrUrlBuilder.append(sharingUri.getHost()); if (sharingUri.getPort() != 80) { qrUrlBuilder.append(':'); qrUrlBuilder.append(sharingUri.getPort()); } qrUrlBuilder.append(sharingUri.getPath()); boolean first = true; Set<String> names = sharingUri.getQueryParameterNames(); for (String name : names) { if (!"ssid".equals(name)) { if (first) { qrUrlBuilder.append('?'); first = false; } else { qrUrlBuilder.append('&'); } qrUrlBuilder.append(name.toUpperCase(Locale.ENGLISH)); qrUrlBuilder.append('='); qrUrlBuilder.append(sharingUri.getQueryParameter(name).toUpperCase(Locale.ENGLISH)); } } qrUriString = qrUrlBuilder.toString(); break; } ImageView qrImage = container.findViewById(R.id.wifi_qr_code); if (qrUriString != null && qrImage != null) { Utils.debugLog(TAG, "Encoded swap URI in QR Code: " + qrUriString); new QrGenAsyncTask(SwapWorkflowActivity.this, R.id.wifi_qr_code).execute(qrUriString); // Replace all blacks with the background blue. qrImage.setColorFilter(new LightingColorFilter(0xffffffff, getResources().getColor(R.color.swap_blue))); final View qrWarningMessage = container.findViewById(R.id.warning_qr_scanner); if (CameraCharacteristicsChecker.getInstance(this).hasAutofocus()) { qrWarningMessage.setVisibility(View.GONE); } else { qrWarningMessage.setVisibility(View.VISIBLE); } } }
Example 19
Source File: SchemeSecondActivity.java From YCAudioPlayer with Apache License 2.0 | 4 votes |
/** * 协议部分,随便设置 yc://app/?page=main */ @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Uri uri = getIntent().getData(); if (uri != null) { //解析一个url // 完整的url信息 String urlStr = uri.toString(); Log.e( "UrlUtils","url: " + urlStr); // scheme部分 String scheme = uri.getScheme(); Log.e( "UrlUtils","scheme: " + scheme); // host部分 String host = uri.getHost(); Log.e( "UrlUtils","host: " + host); //port部分 int port = uri.getPort(); Log.e( "UrlUtils","port: " + port); // 访问路劲 String path = uri.getPath(); Log.e( "UrlUtils","path: " + path); List<String> pathSegments = uri.getPathSegments(); Log.e( "UrlUtils","pathSegments: " + pathSegments.toString()); // Query部分 String query = uri.getQuery(); Log.e( "UrlUtils","query: " + query); //获取此URI的解码权限部分。对于服务器地址,权限的结构如下:Examples: "google.com", "[email protected]:80" String authority = uri.getAuthority(); Log.e( "UrlUtils","authority: " + authority); //从权限获取已解码的用户信息。例如,如果权限为“任何人@google.com”,此方法将返回“任何人”。 String userInfo = uri.getUserInfo(); Log.e( "UrlUtils","userInfo: " + userInfo); //获取指定参数值 String page = uri.getQueryParameter("page"); Log.e( "UrlUtils","main: " + page); //UrlUtils: url: https://m.dev.haowumc.com/app/financialManagement //UrlUtils: scheme: https //UrlUtils: host: m.dev.haowumc.com //UrlUtils: port: -1 //UrlUtils: path: /app/financialManagement //UrlUtils: pathSegments: [app, financialManagement] //UrlUtils: query: null //UrlUtils: authority: m.dev.haowumc.com //UrlUtils: userInfo: null switch (page){ //yc://app/?page=yangchong case "yangchong": ActivityUtils.startActivity(GuideActivity.class); break; //yc://app/?page=main case "main": readGoActivity(new Intent(this,MainActivity.class),this); break; //yc://app/?page=setting case "setting": readGoActivity(new Intent(this, MeSettingActivity.class),this); break; } } finish(); }
Example 20
Source File: NewRepoConfig.java From fdroidclient with GNU General Public License v3.0 | 4 votes |
private void init(Context context, Uri incomingUri) { /* an URL from a click, NFC, QRCode scan, etc */ Uri uri = incomingUri; if (uri == null) { isValidRepo = false; return; } Utils.debugLog(TAG, "Parsing incoming intent looking for repo: " + incomingUri); // scheme and host should only ever be pure ASCII aka Locale.ENGLISH String scheme = uri.getScheme(); host = uri.getHost(); port = uri.getPort(); if (TextUtils.isEmpty(scheme) || (TextUtils.isEmpty(host) && !"file".equals(scheme))) { errorMessage = String.format(context.getString(R.string.malformed_repo_uri), uri); Log.i(TAG, errorMessage); isValidRepo = false; return; } if (Arrays.asList("FDROIDREPO", "FDROIDREPOS").contains(scheme)) { /* * QRCodes are more efficient in all upper case, so QR URIs are * encoded in all upper case, then forced to lower case. Checking if * the special F-Droid scheme being all is upper case means it * should be downcased. */ uri = Uri.parse(uri.toString().toLowerCase(Locale.ENGLISH)); } else if (uri.getPath().endsWith("/FDROID/REPO")) { /* * some QR scanners chop off the fdroidrepo:// and just try http://, * then the incoming URI does not get downcased properly, and the * query string is stripped off. So just downcase the path, and * carry on to get something working. */ uri = Uri.parse(uri.toString().toLowerCase(Locale.ENGLISH)); } // make scheme and host lowercase so they're readable in dialogs scheme = scheme.toLowerCase(Locale.ENGLISH); host = host.toLowerCase(Locale.ENGLISH); if (uri.getPath() == null || !Arrays.asList("https", "http", "fdroidrepos", "fdroidrepo", "content", "file").contains(scheme)) { isValidRepo = false; return; } String userInfo = uri.getUserInfo(); if (userInfo != null) { String[] userInfoTokens = userInfo.split(":"); if (userInfoTokens != null && userInfoTokens.length >= 2) { username = userInfoTokens[0]; password = userInfoTokens[1]; for (int i = 2; i < userInfoTokens.length; i++) { password += ":" + userInfoTokens[i]; } } } fingerprint = uri.getQueryParameter("fingerprint"); bssid = uri.getQueryParameter("bssid"); ssid = uri.getQueryParameter("ssid"); fromSwap = uri.getQueryParameter("swap") != null; uriString = sanitizeRepoUri(uri); isValidRepo = true; }