问题: 为什么以编程方式创建的“短动态链接”无法直接打开/启动应用程序?
但是在控制台上创建的链接仅显示一个提示来选择浏览器,然后直接启动应用程序。
当用户单击由android应用程序动态创建的动态网址时,我想直接启动应用程序。
点击由android应用动态创建的动态短链接时,会发生以下情况,
1。在浏览器显示中打开的选项
2。浏览器打开,显示一个加载对话框
3.Again再次显示在浏览器中打开的选项(这次应用程序显示在更多选项区域中)
4。单击浏览器打开网站,单击应用程序启动应用程序,但深层链接丢失。
任何帮助都很好。
Manifest.xml
...
<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="notifika.tupio.me"
android:scheme="https" />
</intent-filter>
...
链接生成
public void createDynamicLink(final Context context, final SingleNotification notification){
final Uri[] mInvitationUrl = {null};
String link = "https://notifika.tupio.me/?public=" + notification.getTag();
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))
.setDynamicLinkDomain("notifika.page.link")
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder("me.tupio.notifika")
.build())
.setGoogleAnalyticsParameters(
new DynamicLink.GoogleAnalyticsParameters.Builder()
.setSource("In-App")
.setMedium("social")
.setCampaign("Word-Word")
.build())
.setSocialMetaTagParameters(
new DynamicLink.SocialMetaTagParameters.Builder()
.setTitle("Notifika")
.setDescription("Sent and Receive Notification like this.Download the app now")
.build())
.buildShortDynamicLink()
.addOnSuccessListener(new OnSuccessListener<ShortDynamicLink>() {
@Override
public void onSuccess(ShortDynamicLink shortDynamicLink) {
mInvitationUrl[0] = shortDynamicLink.getShortLink();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, notification.getTitle()+"\n"+notification.getMessage().substring(0, Math.min(notification.getMessage().length(), 100)) + "..." +context.getResources().getString(R.string.share_link_desc)+"\n"+mInvitationUrl[0]);
context.startActivity(Intent.createChooser(intent, "Share"));
}
});
}
MainActivity.class
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
@Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
Log.v("Deeplink",deepLink.toString());
}
//
// If the user isn't signed in and the pending Dynamic Link is
// an invitation, sign in the user anonymously, and record the
// referrer's UID.
//
if (deepLink != null
&& deepLink.getBooleanQueryParameter("public",false)) {
String referrerUid = deepLink.getQueryParameter("public");
Log.v("Deeplink", referrerUid);
Toast.makeText(getApplicationContext(),referrerUid,Toast.LENGTH_LONG).show();
}
}
});
遵循this指南。
答案 0 :(得分:3)
您还需要为page.link/app.goo.gl域添加一个意图过滤器,因此深层链接直接进入您的应用。参见:https://firebase.google.com/docs/dynamic-links/android/receive#app_links