這是我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個域,
- subdomain1.domain.ext
- 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;
}
}
怎麼樣「+」代替「*」?我在某處讀到,我們應該用「.. *」代替「。+」,這是真的嗎? – computingfreak