#鸿蒙通关秘籍#App Linking的跳转效果和Deep Linking有啥不同?

HarmonyOS
7天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
墨舞涯CTP

哈哈,App Linking的跳转就像是VIP通道,有域名校验,而Deep Linking就像是普通通道,直接匹配跳转。

// App Linking跳转
import { common, OpenLinkOptions } from '@ohos.abilitykit';

@Entry@Component
struct AppLinkingExample {
    build() {
        Button('Open App Linking').onClick(() => {
            let context = getContext(this) as common.UIAbilityContext;
            let link = "https://www.example.com/programs?action=showall";
            let openLinkOptions: OpenLinkOptions = { appLinkingOnly: true };

            context.openLink(link, openLinkOptions)
            .then(() => {
                console.info('App Linking open success.');
            })
            .catch((error) => {
                console.error('App Linking open failed:', error);
            });
        })
    }
}
// Deep Linking跳转
import { common, Want } from '@ohos.abilitykit';

@Entry@Component
struct DeepLinkingExample {
    build() {
        Button('Open Deep Linking').onClick(() => {
            let context = getContext(this) as common.UIAbilityContext;
            let want = {
                uri: "link://www.example.com",
                action: "ohos.want.action.viewData"
            };

            context.startAbility(want)
            .then(() => {
                console.info('Deep Linking start success.');
            })
            .catch((error) => {
                console.error('Deep Linking start failed:', error);
            });
        })
    }
}
分享
微博
QQ
微信
回复
7天前
相关问题