gpt4 book ai didi

android - 如何在Android应用程序中设置指向特定 Activity 的动态链接

转载 作者:行者123 更新时间:2023-11-29 15:00:44 24 4
gpt4 key购买 nike

我正在实现一个购物应用程序。当一个产品被共享时,它应该发送一个动态链接,这样当一个人点击它时,只在应用程序中打开。最后我实现了这个功能。但是当我从共享动态链接我正在获取主页而不是产品页面。我需要有关获取特定产品页面而不是打开购物主页的帮助。我在这里包括代码。 AndroidManifest.xml

<activity android:name=".Postdetails">
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="MainActivity" />
<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="postdetailsnew.com" android:scheme="https"
android:pathPattern=".*"/>
</intent-filter>
</activity>

PostDetails.java Here PostDetails 页面是单个产品设计页面或 Activity 。在此我编写了以下代码。

sharebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
s="https://app_code.app.goo.gl/?link="+ProductLinkInBrowser+"&apn=com.example.maneesh.shop";
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, s);
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
}
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();
FirebaseAppInvite invite=FirebaseAppInvite.getInvitation(pendingDynamicLinkData);
if(invite!=null){
String invitationId=invite.getInvitationId();
}
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w("Heyy", "getDynamicLink:onFailure", e);
}
});

所以这里终于打开了带有动态链接的应用程序主页,而不是共享的特定产品页面。请指导我实现这一点。

最佳答案

您需要解析动态链接中的 URL,并触发 intent 以将用户引导至您应用的正确部分。通常,您会在主要 Activity 中设置动态链接监听器,并将从那里路由到任何特定需求。

代码中的 deepLink 变量将是您在动态链接中传递的 URL,例如 http://yourshop.com/product/12345。您可以调用 deepLink.getPath(),它会返回给您product/12345,然后触发并执行此操作,例如:

String path = deepLink.getPath();
String[] parts = path.split("/")
if (parts[0] == "product") {
Intent intent = new Intent(this, PostDetails.class);
intent.putExtra("productid", parts[1]);
startActivity(intent);
}

关于android - 如何在Android应用程序中设置指向特定 Activity 的动态链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46246058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com