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

相關問題