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

HarmonyOS
2024-12-05 13:01:50
717浏览
收藏 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);
});
})
}
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.

// 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);
            });
        })
    }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
已于2024-12-19 17:09:47修改
分享
微博
QQ
微信
回复
2024-12-05 15:24:51


相关问题
HarmonyOS App Linking测试链接
801浏览 • 1回复 待解决