0

这是我AndroidManifest.xml文件Android应用程序链接具有多个域开展同样的活动

<activity 
    android:name=".activity.LaunchActivity" 
    android:autoVerify="true" 
    android:configChanges="orientation|keyboardHidden|screenSize|screenLayout" 
    android:label="@string/app_name" 
    android:noHistory="true"> 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
    <intent-filter> 
     <action android:name="android.intent.action.VIEW" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <category android:name="android.intent.category.BROWSABLE" /> 
     <data 
      android:host="subdomain1.domain.ext" 
      android:path="/path1/subpath1/.*" 
      android:scheme="https" /> 
    </intent-filter> 
    <intent-filter> 
     <action android:name="android.intent.action.VIEW" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <category android:name="android.intent.category.BROWSABLE" /> 
     <data 
      android:host="subdomain1.domain.ext" 
      android:pathPattern="/path2/subpath2/..*" 
      android:scheme="https" /> 
    </intent-filter> 
    <intent-filter> 
     <action android:name="android.intent.action.VIEW" /> 

     <category android:name="android.intent.category.DEFAULT" /> 
     <category android:name="android.intent.category.BROWSABLE" /> 

     <data 
      android:host="subdomain2.subdomain1.domain.ext" 
      android:pathPattern="^..*" 
      android:scheme="https" /> 
    </intent-filter> 
</activity> 
<activity 
    android:name=".activity.LoginActivity" 
    android:configChanges="orientation|keyboardHidden|screenSize|screenLayout" 
    android:label="@string/app_name" /> 
<activity 
    android:name=".activity.MainActivity" 
    android:configChanges="orientation|keyboardHidden|screenSize|screenLayout" 
    android:label="@string/app_name" /> 

我想使用Android应用程序链接2个域,

  1. subdomain1.domain.ext
  2. subdomain2 .subdomain1.domain.ext

我已经将assetlinks.json文件放在b OTH

subdomain1.domain.ext/.well-known/assetlinks.json 

subdomain2.subdomain1.domain.ext/.well-known/assetlinks.json 

但在使用Android Studio中, 我看不到任何命中要么文件Apache服务器的访问日志安装的应用程序。

请注意,我使用的发行版本变体使用了用于在assetlinks.json中生成SHA256指纹的相同密钥库文件。

当我有联系,如

https://subdomain1.domain.ext/path1/subpath1/ 

https://subdomain2.subdomain1.domain.ext/path2 

仅测试下一个启动应用程序,前者只需在浏览器中打开。 因此,似乎代码的最后一行(第二主机)设置为应用程序链接。

Qn 1。如何在具有相同活动的单独主机上打开两个路径/链接?在我的情况下,我如何使第一个链接也打开应用程序?

Qn 2。我想限制在应用程序中打开一些链接,我试过这个正则表达式作为路径模式,但它没有工作。我知道它是一个glob,有没有可能做到这一点?

android:pathPattern="^(?!foo|bar)..*$" 

排除有foo和酒吧开始,但让别人链接路径。

我想打开

example.com in web browser 
example.com/test in web browser 
example.com/test/temp in web browser 
example.com/{anything else} in the app 

我读到这个其他计算器帖子:

但我没有任何查询参数。我的情况是非常类似于Android Deep linking omit certain url

QN 3描述。是否强制对于定义此类应用链接的意图过滤器(Web链接启动应用)的活动包含action = MAIN和category = LAUNCHER?

<action android:name="android.intent.action.MAIN" /> 
<category android:name="android.intent.category.LAUNCHER" /> 

期待一些帮助。对于Android团队来说,如果不允许排除路径,这似乎太愚蠢了,应该从Apple的服务器端文件中学习,该文件使用简单的NOT子句。

在情况下,它可以帮助, 这是在OnCreate Java代码(LaunchActivity

public class LaunchActivity extends AppCompatActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splashscreen); 
     Intent intent = getIntent(); 
     if (intent != null) { 
      Uri target = intent.getData(); 
      if (target != null && target.isHierarchical()) { 
       String goal = intent.getDataString(); 
       List<String> params = target.getPathSegments(); 
       Log.d(TAG, "app uri : " + goal); 
       Log.d(TAG, "app link : " + target.toString()); 
       Log.d(TAG, "path segments : " + params); 
       if (target.toString().startsWith(MON_DOM)) { 
        if (searchString(AppLinksUtil.TARGET_URLS, target.toString())) { 
         Log.d(TAG, "Open TARGET Link in APP"); 
        } else { 
         Log.d(TAG, "Open Excluded Link in Browser"); 
         openLinkInChrome(LaunchActivity.this, goal); 
         finish(); 
        } 
       } else if (target.toString().startsWith(ENQ_DOM)) { 
        Log.d(TAG, "Exclude List : " + AppLinksUtil.ENQ_EXCLUDE_URLS); 
        if (searchString(AppLinksUtil.EXCLUDE_URLS, target.toString())) { 
         Log.d(TAG, "Open Excluded Link in Browser"); 
         openLinkInChrome(LaunchActivity.this, goal); 
         finish(); 
        } else { 
         Log.d(TAG, "Open Link in APP"); 
        } 
       } 
      } 
     } else { 
      Log.d(TAG, "no intent"); 
     } 
     appFlow(); 
    } 
    ... 
    public void openLinkInChrome(final Activity activity, String link) { 
     Log.d(TAG, "Opening " + link + " in web browser"); 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link)); 
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     intent.setPackage("com.android.chrome"); 
     try { 
      activity.startActivity(intent); 
     } catch (ActivityNotFoundException ex) { 
      intent.setPackage(null); 
      activity.startActivity(intent); 
     } 
    } 
    public static boolean searchString(String[] arr, String targetValue) { 
     for (String s : arr) { 
      if (targetValue.startsWith(s)) 
       return true; 
     } 
     return false; 
    } 
} 

回答

0

在尝试一些代码的变化我意识到

对于1,没有为同一个域的子域NO通配符选项,多个域的支持,列出他们一个接一个用正确pathPatterns修复的问题我正面临着。

AndroidManifest.xml

<activity android:name="MainActivity"> 
<intent-filter> 
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 
    <data android:scheme="http" /> 
    <data android:host="subdomain1.example1.com" /> 
    <data android:host="subdomain2.example1.com" /> 
    <data android:host="subdomain3.example2.com" /> 
    <data android:path="/onlythis" /> 
    <data android:pathPrefix="/starter" /> 
    <data android:pathPattern="/prefix.*" /> 
    <data android:pathPattern="/.*suffix" /> 
</intent-filter> 
</activity> 

为2,路径的排除是不可能的是,谷歌必须从苹果学习。

对于3,任何活动都可以链接,而不仅仅是主要/启动者之一。

action = MAIN和category = LAUNCHER不适用于应用链接代码, action = VIEW以及category = DEFAULT和BROWSABLE是必需且足够的。

因此,不同的域/子域只要能推出不同的活动,视为违约,可浏览与动作一起定义= VIEW

0

pathPattern的 )方法不支持完整的正则表达式的特征。它只支持“*”和“。*”。而已。

pathPatternhttps://developer.android.com/guide/topics/manifest/data-element.html

pathPattern属性指定针对在Intent对象的完整路径匹配 一个完整路径中的描述,但它可以包含 以下通配符:

  • 星号('*')将0的序列与前一个字符出现的次数相匹配。
  • 周期后跟星号(“。*”)匹配0到多个字符的任何序列。

https://developer.android.com/reference/android/os/PatternMatcher.html#PATTERN_SIMPLE_GLOB


见,只要你想对给定<activity>你可以有很多<intent-filter>秒。由于您无法使用正则表达式来描述所需的不同网址,因此只需为每个网址创建一个单独的<intent-filter>描述。

+0

怎么样“+”代替“*”?我在某处读到,我们应该用“.. *”代替“。+”,这是真的吗? – computingfreak

相关问题