【问题标题】:Pattern matching for Android deep linksAndroid 深层链接的模式匹配
【发布时间】:2020-02-03 14:20:49
【问题描述】:

我的应用必须验证网络链接和深层链接等 Uris。

对于像https://www.google.com 这样的网络链接,我发现这很有用:

boolean validWebUrl =Patterns.WEB_URL.matcher(url).matches();

但在用于 appname://suitablestring 等深层链接时会产生负值

上面的深层链接指令相当于什么?

【问题讨论】:

    标签: java android regex uri deep-linking


    【解决方案1】:

    我认为网页 url 匹配是基于检查诸如 http:// https:// 之类的字符串。

    因此,出于我的目的,我发现这种解决方法可能很有用:

    Uri url =Uri.parse(urlString);
    Intent browserIntent = new Intent();
    browserIntent.setData(url);
    browserIntent.setAction(ACTION_VIEW);
    
    try {
    activity.startActivity(browserIntent);
    }
    catch (ActivityNotFoundException e)
    {
    
    boolean validWebUrl =
            Patterns.WEB_URL.matcher(urlString).matches();
    if (!validWebUrl)
        {          
          openAlertDialog(activity,activity.getResources().getString(R.string.url_not_valid_dialog_title),activity.getResources().getString(R.string.url_not_valid_error_message));
        }
    else {
          openAlertDialog(activity,activity.getResources().getString(R.string.activity_not_found_for_url_dialog_title),activity.getResources().getString(R.string.activity_not_found_for_url_message));
         }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多