英文:
Deep link not opening specified Activity but opens other Activity
问题
我已经通过编程方式创建了一个DynamicLink
,其中包括子域名语法、一些标题和预览图像。我还指定了当链接被点击时应该打开的IntentFilter
。但是当点击链接时,它会打开另一个具有深层链接的活动。页面链接域名由谷歌在Firebase控制台中提供。创建动态链接的代码如下:
String e = "https://learnandroid.page.link/?link=https://learn.android/&apn=com.learnandro&amv=16&st=Please view the ContentEvent&si=" + some Image Url + "&afl=https://play.google.com/store/apps/details?id=app Package name";
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance()
.createDynamicLink()
.setLongLink(Uri.parse(e))
.buildShortDynamicLink()
.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
@Override
public void onComplete(@NonNull Task<ShortDynamicLink> task) {
Uri get = task.getResult().getShortLink();
Intent sh = new Intent(Intent.ACTION_SEND);
sh.setType("text/plain");
sh.putExtra(Intent.EXTRA_TEXT, "View the Amazing Event " + get);
startActivity(Intent.createChooser(sh, "View"));
}
});
活动的意图过滤器如下:
<activity android:name=".content.Home"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<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="learn.android"
android:scheme="https" />
</intent-filter>
</activity>
但是,当点击生成的链接时,它会打开另一个活动。
英文:
I have created a DynamicLink
programatically which includes sub-domain syntax, some title and preview Image. I have also specified the IntentFilter
which should open that activity when clicked. But when the link is clicked it open another Activity which also have Deep link. page.link domain is provided by google itself in Firebase Console
The code for creating Dynamic Link is
String e="https://learnandroid.page.link/?link=https://learn.android/&apn=com.learnandro&amv=16&st=Please view the ContentEvent&si="+some Image Url+"&afl=https://play.google.com/store/apps/details?id=app Package name";
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance()
.createDynamicLink()
.setLongLink(Uri.parse(e))
.buildShortDynamicLink()
.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
@Override
public void onComplete(@NonNull Task<ShortDynamicLink> task) {
Uri get=task.getResult().getShortLink();
Intent sh=new Intent(Intent.ACTION_SEND);
sh.setType("text/plain");
sh.putExtra(Intent.EXTRA_TEXT,"Vi ew the Amazing Event "+get);
startActivity(Intent.createChooser(sh,"View"));
}
});
The Intent filter for Activity is given as
<activity android:name=".content.Home"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<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="learn.android"
android:scheme="https" />
</intent-filter>
</activity>
But when the link generated is clicked it opens some Another activity.
答案1
得分: 1
如果您在多个活动中使用深链接,则应使用 android:pathPattern
将它们区分开来。
以下是示例代码:
<data
android:host="learn.android"
android:pathPattern="/home"
android:scheme="https" />
然后将 /home
添加到您的链接中:
String e = "https://learnandroid.page.link/?link=https://learn.android/home/&apn=com.learnandro&amv=16&st=Please view the ContentEvent&si=" + 某个图片网址 + "&afl=https://play.google.com/store/apps/details?id=应用程序包名";
英文:
If you have deeplink in multiple activities then you should use android:pathPattern
to differentiate them from each other.
Here is sample code
<data
android:host="learn.android"
android:pathPattern="/home"
android:scheme="https" />
and add /home
to your link
String e="https://learnandroid.page.link/?link=https://learn.android/home/&apn=com.learnandro&amv=16&st=Please view the ContentEvent&si="+some Image Url+"&afl=https://play.google.com/store/apps/details?id=app Package name";
答案2
得分: 0
以下是已翻译的内容:
您可以尝试以下代码片段:
val data: Uri? = intent?.data
if (Uri.EMPTY != data)
{
val id = intent.data?.getQueryParameter("ID")
intent = Intent(this, ActivityName::class.java)
startActivity(intent)
finish()
}
- 在 getQueryParameter 中,您需要传递包含 URL 中数据的键名
- 在清单文件中定义此代码集合的活动
英文:
You can try below snippet :
val data: Uri? = intent?.data
if (Uri.EMPTY != data)
{
val id = intent.data?.getQueryParameter("ID")
intent = Intent(this, ActivityName::class.java)
startActivity(intent)
finish()
}
- In getQueryParameter, you need to pass KEY name which contains data in URL
- Define this set of code in Activity which is defined in Manifest file
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论