
回复
applinking.json
文件验证域名归属场景 | 应用示例 | 优势 |
---|---|---|
扫码直达 | 扫码打开商品详情 | 防恶意链接 |
社交分享 | 分享应用内页面到社交平台 | 已安装直接打开,未安装跳转下载页 |
广告引流 | 点击广告直达应用内活动 | 精准追踪来源 |
.well-known/applinking.json
"app_id": "your_app_id_here"
harmony.example.com
)import { UIAbility, Want } from '@ohos.app.ability.common';
import { url } from '@ohos.arkts';
export default class EntryAbility extends UIAbility {
onCreate(want: Want) {
const uri = want.uri;
if (uri) {
const urlObj = url.URL.parseURL(uri);
const action = urlObj.params.get('action');
switch(action) {
case 'product': this.openProductDetail(urlObj.params.get('id'));
case 'event': this.openEventPage(urlObj.params.get('eventId'));
}
}
}
}
import { common } from '@ohos.app.ability.common';
const context = this.getContext(this) as common.UIAbilityContext;
const link = 'https://harmony.example.com/shop/product?id=123';
const options = {
appLinkingOnly: true, // 强制使用App Linking
openInBrowser: true // 域名校验失败时跳转浏览器
};
context.openLink(link, options);
系统会自动处理未安装情况:
// 生成带参数的App Linking
const generateProductLink = (productId: string) => {
return `https://harmony.example.com/product?id=${productId}&action=view`;
};
// 扫码后跳转
context.openLink(generateProductLink('P001'), { appLinkingOnly: true });
// 分享带参链接
const shareLink = 'https://harmony.example.com/event?eid=567&from=social';
shareToWeChat(shareLink);
// 应用内处理分享链接
onCreate(want) {
const eid = url.URL.parseURL(want.uri).params.get('eid');
this.loadEventDetail(eid);
}
.well-known
下App Linking通过域名校验和HTTPS加密,实现了安全可靠的应用间跳转。开发者只需四步配置(AGC开通→服务器验证→域名关联→应用内处理),即可在扫码、分享等场景中提供安全的一键直达体验,同时自动处理未安装场景,提升用户转化率和安全性。