请告诉我Manifest文件中的意图过滤器用于深度链接。
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="packagename"
android:scheme="android-app" />
</intent-filter>
我可能会选择DeepLinkDispatch这样的库,它简化了深链接配置的设置和维护。
来自README.md
@DeepLink("foo://example.com/deepLink/{id}")
public class MainActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent().getBooleanExtra(DeepLink.IS_DEEP_LINK, false)) {
Bundle parameters = getIntent().getExtras();
String idString = parameters.getString("id");
// Do something with the ID...
}
}
}
并且不会污染您的清单,因为只有一个活动被声明
<activity
android:name="com.airbnb.deeplinkdispatch.DeepLinkActivity"
android:theme="@android:style/Theme.NoDisplay">
<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="airbnb" />
</intent-filter>
</activity>