Java Code Examples for android.net.Uri#getUserInfo()

The following examples show how to use android.net.Uri#getUserInfo() . 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: NewRepoConfig.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sanitize and format an incoming repo URI for function and readability.
 * This also forces URLs listed in {@code app/src/main/res/xml/network_security_config.xml}
 * to have "https://" as the scheme.
 *
 * @see <a href="https://developer.android.com/training/articles/security-config">Network Security Config</a>
 */
public static String sanitizeRepoUri(Uri uri) {
    String scheme = uri.getScheme();
    String newScheme = scheme.toLowerCase(Locale.ENGLISH);
    String host = uri.getHost();
    String newHost = host.toLowerCase(Locale.ENGLISH);
    String userInfo = uri.getUserInfo();
    if ("http".equals(newScheme)) {
        for (String httpsDomain : FORCE_HTTPS_DOMAINS) {
            if (newHost.endsWith(httpsDomain)) {
                scheme = "https";
                break;
            }
        }
    }

    return uri.toString()
            .replaceAll("\\?.*$", "") // remove the whole query
            .replaceAll("/*$", "") // remove all trailing slashes
            .replace(userInfo + "@", "") // remove user authentication
            .replaceFirst(host, newHost)
            .replaceFirst(scheme, newScheme)
            .replace("fdroidrepo", "http") // proper repo address
            .replace("/FDROID/REPO", "/fdroid/repo"); // for QR FDroid path
}
 
Example 2
Source File: ShadowsocksConfig.java    From shadowsocks-android-java with Apache License 2.0 6 votes vote down vote up
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];
        }
    }
    if (!CryptFactory.isCipherExisted(config.EncryptMethod)) {
        throw new Exception(String.format("Method: %s does not support", config.EncryptMethod));
    }
    config.ServerAddress = new InetSocketAddress(uri.getHost(), uri.getPort());
    return config;
}
 
Example 3
Source File: CommonUtil.java    From Aria with Apache License 2.0 6 votes vote down vote up
/**
 * 分割获取url,协议,ip/域名,端口,内容
 *
 * @param url 输入的url{@code String url = "ftp://z:[email protected]:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv";}
 */
public static FtpUrlEntity getFtpUrlInfo(String url) {
  Uri uri = Uri.parse(url);

  String userInfo = uri.getUserInfo(), remotePath = uri.getPath();
  ALog.d(TAG,
      String.format("scheme = %s, user = %s, host = %s, port = %s, path = %s", uri.getScheme(),
          userInfo, uri.getHost(), uri.getPort(), remotePath));

  FtpUrlEntity entity = new FtpUrlEntity();
  entity.url = url;
  entity.hostName = uri.getHost();
  entity.port = uri.getPort() == -1 ? "21" : String.valueOf(uri.getPort());
  if (!TextUtils.isEmpty(userInfo)) {
    String[] temp = userInfo.split(":");
    if (temp.length == 2) {
      entity.user = temp[0];
      entity.password = temp[1];
    } else {
      entity.user = userInfo;
    }
  }
  entity.scheme = uri.getScheme();
  entity.remotePath = TextUtils.isEmpty(remotePath) ? "/" : remotePath;
  return entity;
}
 
Example 4
Source File: ShadowsocksConfig.java    From SmartZPN with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 5
Source File: ShadowsocksConfig.java    From SmartProxy with GNU General Public License v3.0 6 votes vote down vote up
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: HttpConnectConfig.java    From shadowsocks-android-java with Apache License 2.0 5 votes vote down vote up
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 7
Source File: HttpConnectConfig.java    From VpnProxy with MIT License 5 votes vote down vote up
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: HttpConnectConfig.java    From BaoLianDeng with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: HttpConnectConfig.java    From SmartZPN with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 10
Source File: HttpConnectConfig.java    From SmartProxy with GNU General Public License v3.0 5 votes vote down vote up
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 11
Source File: AppManagerSchema.java    From AppManager-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * "https://{basicAuthUser}:{basicAuthPassword}@import-to-appmanager/github.com/app-manager/AppManager-for-Android/blob/master/tests/apk/dummy.apk?raw=true#{name}"
 * to
 * "https://github.com/app-manager/AppManager-for-Android/blob/master/tests/apk/dummy.apk?raw=true"
 *
 * @param uri
 * @return decoded FileEntry, or null if it was not able to decode uri.
 */
public static FileEntry decode(String uri) {
    FileEntry entry;
    // validate url
    try {
        Uri encodedUri = Uri.parse(uri);

        String specialHost = encodedUri.getHost();
        if (!matchesSpecialHosts(specialHost)) {
            throw new UnsupportedOperationException("host is not '" + getSpecialHostsList() + "'");
        }
        entry = new FileEntry();
        entry.name = encodedUri.getFragment(); // null if not include
        String userInfo = encodedUri.getUserInfo();
        if (null != userInfo) {
            String[] parts = userInfo.split(":");
            String basicAuthUser = parts[0];
            String basicAuthPassword = parts[1];
            if (!TextUtils.isEmpty(basicAuthUser) && !TextUtils.isEmpty(basicAuthPassword)) {
                entry.basicAuthUser = basicAuthUser;
                entry.basicAuthPassword = basicAuthPassword;
            }
        }

        String schema = encodedUri.getScheme();
        String encodedPath = encodedUri.getPath();
        int separatePoint = encodedPath.indexOf("/");
        String host = encodedPath.substring(0, separatePoint);
        String path = encodedPath.substring(separatePoint + 1);
        String query = encodedUri.getQuery();
        if (TextUtils.isEmpty(query)) {
            entry.url = schema + "://" + host + path;
        } else {
            entry.url = schema + "://" + host + path + "?" + query;
        }

        return entry;
    } catch (Exception e) {
        LogUtils.e(TAG, e.getMessage(), e);
        return null;
    }
}
 
Example 12
Source File: UrlUtils.java    From YCAudioPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * 拼接字符串
 * @param url                       url
 * @param map                       map集合
 * @return
 */
public static String getUrl(String url, HashMap<String, String> map){
    if(TextUtils.isEmpty(url)){
        return null;
    }
    //解析一个url
    Uri uri = Uri.parse(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);


    //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

    Uri.Builder builder = uri.buildUpon();
    if (map != null && map.size() > 0) {
        //使用迭代器进行遍历
        for (Object o : map.entrySet()) {
            Map.Entry entry = (Map.Entry) o;
            String key = (String) entry.getKey();
            String value = (String) entry.getValue();
            //对键和值进行编码,然后将参数追加到查询字符串中。
            builder.appendQueryParameter(key, value);
        }
    }
    return builder.toString();
}
 
Example 13
Source File: NewRepoConfig.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 14
Source File: ManageReposActivity.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
private void showAddRepo() {
    /*
     * If there is text in the clipboard, and it looks like a URL, use that.
     * Otherwise use "https://" as default repo string.
     */
    String text = getPrimaryClipAsText();
    String fingerprint = null;
    String username = null;
    String password = null;
    if (!TextUtils.isEmpty(text)) {
        try {
            new URL(text);
            Uri uri = Uri.parse(text);
            fingerprint = uri.getQueryParameter("fingerprint");
            // uri might contain a QR-style, all uppercase URL:
            if (TextUtils.isEmpty(fingerprint)) {
                fingerprint = uri.getQueryParameter("FINGERPRINT");
            }

            String userInfo = uri.getUserInfo();
            if (userInfo != null) {
                String[] userInfoTokens = userInfo.split(":");
                if (userInfoTokens.length >= 2) {
                    username = userInfoTokens[0];
                    password = userInfoTokens[1];
                    for (int i = 2; i < userInfoTokens.length; i++) {
                        password += ":" + userInfoTokens[i];
                    }
                }
            }

            text = NewRepoConfig.sanitizeRepoUri(uri);
        } catch (MalformedURLException e) {
            text = null;
        }
    }

    if (TextUtils.isEmpty(text)) {
        text = DEFAULT_NEW_REPO_TEXT;
    }
    showAddRepo(text, fingerprint, username, password);
}
 
Example 15
Source File: SipService.java    From pjsip-android with Apache License 2.0 4 votes vote down vote up
private void handleMakeDirectCall(Intent intent) {
    Bundle bundle = intent.getExtras();
    if (bundle == null) return;
    Uri uri = bundle.getParcelable(PARAM_DIRECT_CALL_URI);
    if (uri == null) return;
    String sipServer = intent.getStringExtra(PARAM_DIRECT_CALL_SIP_SERVER);
    String name = intent.getStringExtra(PARAM_GUEST_NAME);
    boolean isVideo = intent.getBooleanExtra(PARAM_IS_VIDEO, false);
    boolean isVideoConference = false;
    if (isVideo) {
        isVideoConference = intent.getBooleanExtra(PARAM_IS_VIDEO_CONF, false);
    }

    Logger.debug(TAG, "Making call to " + uri.getUserInfo());
    String accountID = "sip:"+name+"@"+uri.getHost();
    String sipUri = "sip:" + uri.getUserInfo()+"@"+uri.getHost();

    try {
        startStack();
        SipAccountData sipAccountData = new SipAccountData()
                .setHost(sipServer != null ? sipServer : uri.getHost())
                .setUsername(name)
                .setPort((uri.getPort() > 0) ? uri.getPort() : 5060)
                .setRealm(uri.getHost());
                /* display name not yet implemented server side for direct calls */
                /* .setUsername("guest") */
                /* .setGuestDisplayName(name)*/
        SipAccount pjSipAndroidAccount = new SipAccount(this, sipAccountData);
        pjSipAndroidAccount.createGuest();
        mConfiguredGuestAccount = pjSipAndroidAccount.getData();

        // Overwrite the old value if present
        mActiveSipAccounts.put(accountID, pjSipAndroidAccount);

        SipCall call = mActiveSipAccounts.get(accountID).addOutgoingCall(sipUri, isVideo, isVideoConference);
        if (call != null) {
            call.setVideoParams(isVideo, isVideoConference);
            mBroadcastEmitter.outgoingCall(accountID, call.getId(), uri.getUserInfo(), isVideo, isVideoConference);
        } else {
            Logger.error(TAG, "Error while making a direct call as Guest");
            mBroadcastEmitter.outgoingCall(accountID, -1, uri.getUserInfo(), false, false);
        }
    } catch (Exception ex) {
        Logger.error(TAG, "Error while making a direct call as Guest", ex);
        mBroadcastEmitter.outgoingCall(accountID, -1, uri.getUserInfo(), false, false);
        Crashlytics.logException(ex);
    }
}
 
Example 16
Source File: AdvancedWebView.java    From Android-AdvancedWebView with MIT License 4 votes vote down vote up
public boolean isPermittedUrl(final String url) {
	// if the permitted hostnames have not been restricted to a specific set
	if (mPermittedHostnames.size() == 0) {
		// all hostnames are allowed
		return true;
	}

	final Uri parsedUrl = Uri.parse(url);

	// get the hostname of the URL that is to be checked
	final String actualHost = parsedUrl.getHost();

	// if the hostname could not be determined, usually because the URL has been invalid
	if (actualHost == null) {
		return false;
	}

	// if the host contains invalid characters (e.g. a backslash)
	if (!actualHost.matches("^[a-zA-Z0-9._!~*')(;:&=+$,%\\[\\]-]*$")) {
		// prevent mismatches between interpretations by `Uri` and `WebView`, e.g. for `http://evil.example.com\.good.example.com/`
		return false;
	}

	// get the user information from the authority part of the URL that is to be checked
	final String actualUserInformation = parsedUrl.getUserInfo();

	// if the user information contains invalid characters (e.g. a backslash)
	if (actualUserInformation != null && !actualUserInformation.matches("^[a-zA-Z0-9._!~*')(;:&=+$,%-]*$")) {
		// prevent mismatches between interpretations by `Uri` and `WebView`, e.g. for `http://evil.example.com\@good.example.com/`
		return false;
	}

	// for every hostname in the set of permitted hosts
	for (String expectedHost : mPermittedHostnames) {
		// if the two hostnames match or if the actual host is a subdomain of the expected host
		if (actualHost.equals(expectedHost) || actualHost.endsWith("." + expectedHost)) {
			// the actual hostname of the URL to be checked is allowed
			return true;
		}
	}

	// the actual hostname of the URL to be checked is not allowed since there were no matches
	return false;
}
 
Example 17
Source File: SchemeFirstActivity.java    From YCAudioPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * 协议部分,随便设置 yc://ycbjie.cn:8888/from?type=yangchong
 * 如果携带参数,则:yc://ycbjie.cn:8888/from?type=yangchong&level=20
 */

@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 type = uri.getQueryParameter("type");
        Log.e( "UrlUtils","type: " + type);

        //获取指定参数值,该方法获取值一直是空
        //String level = uri.getQueryParameter("level");
        ///Log.e( "UrlUtils","level: " + level);

        String level = getValueByName(urlStr, "level");
        Log.e( "UrlUtils","level: " + level);


        switch (type){
            //yc://ycbjie.cn:8888/from?type=yangchong
            case "yangchong":
                ActivityUtils.startActivity(GuideActivity.class);
                break;
            //yc://ycbjie.cn:8888/from?type=main
            case "main":
                readGoActivity(new Intent(this,MainActivity.class),this);
                break;
            //yc://ycbjie.cn:8888/from?type=setting
            case "setting":
                readGoActivity(new Intent(this, MeSettingActivity.class),this);
                break;
        }
    }
    finish();
}
 
Example 18
Source File: SchemeSecondActivity.java    From YCAudioPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * 协议部分,随便设置 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();
}