如果有人单击动态链接,我想在选择器应用程序中显示我的应用程序,我的android清单文件应该如何? URL前缀类似于- https://testapp.page.link。在那个阶段,如果有人单击链接,则它首先打开浏览器,然后重定向到我的应用程序。但是我想在选择器应用列表中显示我的应用。这时我的清单文件如下所示:
<activity android:name=".extraActivities.DynamicLinkActivity">
<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="test.com"
android:pathPattern="https://testapp.page.link*"
android:scheme="https"
/>
</intent-filter>
</activity>
答案 0 :(得分:0)
我们需要如下所示在清单文件中写入意图过滤器-
<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="testapp.com"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="testapp.page.link"
android:scheme="https"
android:pathPattern=".*"/>
</intent-filter>
其中“ testapp.page.link”实际上是Firebase动态链接控制台左上角显示的URL前缀。而“ testapp.com”是任何链接的第一部分。例如:https://testapp.com/user_profile?id=“ Zsdsdjwenncsdmsd”。从该链接,我们可以在动态链接的接收端提取用户ID为“ Zsdsdjwenncsdmsd”。完整的示例如下所示-
如果任何人单击共享按钮,将创建动态链接-
shareBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
shareProgressBar.setVisibility(View.VISIBLE);
Task<ShortDynamicLink> shortDynamicLinkTask = buildDeepLink(getString(R.string.grp_post_link)+postsModel.getPostId()+"&groupKey="+postsModel.getGroupKey()+"&groupName="+ dataSnapshot.getValue(String.class));
shortDynamicLinkTask.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
@Override
public void onComplete(@NonNull Task<ShortDynamicLink> task) {
grpPostsViewHolder.shareProgressBar.setVisibility(View.GONE);
if(task.isSuccessful()){
Uri uri = task.getResult().getShortLink();
share(dataSnapshot.getValue(String.class), uri.toString());
}else {
Toast.makeText(context, "Can't create link", Toast.LENGTH_SHORT).show();
}
}
});
shortDynamicLinkTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
shareProgressBar.setVisibility(View.GONE);
}
});
动态链接创建器功能和共享功能-
/*-----------------------------------------------------------------------------*/
private Task<ShortDynamicLink> buildDeepLink(String deepLink) {
String uriPrefix = getString(R.string.dynamic_links_uri_prefix);
return FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(deepLink))
.setDomainUriPrefix(uriPrefix)
.setNavigationInfoParameters(new DynamicLink.NavigationInfoParameters.Builder()
.build())
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder()
.setMinimumVersion(3)
.build())
.buildShortDynamicLink();
}
/*-----------------------------------------------------------------------------*/
private void share(String name, String deepLink) {
String message = "Find "+name+" on SelfieLe - link: "+deepLink;
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(intent);
}
/*---------------------------------------------------------------------------------*/
String资源是-
R.string.grp_post_link和R.string.dynamic_links_uri_prefix:
<string name="user_profile_link">https://testapp.com/user_profile?id=</string>
<string name="dynamic_links_uri_prefix">https://testapp.page.link</string>
在接收端,我们可以如下提取postId,groupKey等
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()).addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
@Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
}
if (deepLink != null) {
getGrpPost(deepLink.getQueryParameter("id"), deepLink.getQueryParameter("groupKey"), deepLink.getQueryParameter("groupName"));
}else {
Toast.makeText(DynamicLinkActivity.this, "Can't find link", Toast.LENGTH_SHORT).show();
}
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(DynamicLinkActivity.this, "Can't find link", Toast.LENGTH_SHORT).show();
}
});
getGroupPost();如下
private void getGrpPost(String id, String groupKey, final String groupName) {
//Do what you want
}
答案 1 :(得分:-1)
请查看以下代码,希望它对您有用,此代码对我当前的应用程序有效:
<activity
android:name=".ActivityName"
android:autoRemoveFromRecents="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden">
<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:host="test.com"
android:pathPrefix="/testapp"
android:scheme="https" />
</intent-filter>
</activity>