After many studies, I decided this. You can use any method.
Refer to the mobile site:. If you want to constantly show your user in Chrome when he is on your msite, you can achieve this by redirecting all your URLs to
Contact in the application
Create a single transparent activity to handle all your deeplinks
Process all links using pathpattern = '. * '
Redirect the user back to Chrome for URLs that you donβt want to handle in the app.
I don't know the exact logic, but it worked.
AndroidManifest.xml
<activity android:name=".DeepLinkActivity" android:noHistory="true" android:theme="@style/Theme.Transparent"> <intent-filter android:autoVerify="true"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="https" /> <data android:scheme="http" /> <data android:scheme="@string/SCHEMA" /> <data android:host="@string/WEB_DOMAIN" /> <data android:host="@string/WWW_WEB_DOMAIN" /> <data android:pathPattern="/.*" /> </intent-filter> </activity>
Deeplink activity
@Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); try { if (Intent.ACTION_VIEW.equals(getIntent().getAction())) { Uri uri = getIntent().getData(); if (uri == null) throw new IllegalArgumentException("Uri can not be null"); Intent intent = null; if (getString(R.string.SCHEMA).equals(uri.getScheme()) || uri.toString().matches(Links.REGEX)) { intent = linkIntent(uri); } if (intent == null) SystemUtil.launchUrlInDefaultBrowser(uri, this); else startActivity(intent); } } catch (IllegalArgumentException e) { Toast.makeText(this, R.string.can_not_open_url, Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(this, R.string.can_not_open_url, Toast.LENGTH_SHORT).show(); } finally { finish(); } } public static void launchUrlInDefaultBrowser(Uri url, Context context) { try { ResolveInfo packageInfo = null; final Intent browserIntent = new Intent(Intent.ACTION_VIEW); browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); browserIntent.setData(url);
source share