扫码直达能力仅支持中国境内(香港特别行政区、澳门特别行政区、中国台湾除外)接入使用。
扫码直达能力仅支持中国境内(香港特别行政区、澳门特别行政区、中国台湾除外)接入使用。
在日常生活中,人们会使用各种应用扫各式各样的码,而“扫码直达”服务则为用户带来一种全新的扫码体验。
开发者将域名注册到“扫码直达”服务后,用户可通过控制中心等系统级的常驻入口,扫应用的二维码、条形码并跳转到应用对应服务页,实现一步直达服务的体验。
开发者接入“扫码直达”服务,能为应用带来:
更浅层的扫码入口和更便捷的“扫码直达”服务体验。
HarmonyOS强大的扫码能力。
更容易触达用户的全新渠道。

开发者参考App Linking指导完成域名注册。
用户通过HarmonyOS扫码入口发起扫码请求。
HarmonyOS扫码入口调用系统能力解析码值,查询码值对应的应用信息后拉起应用。
解析码值结果跳转应用服务页。
参考开发准备完成必要的准备工作。
处理接收到的码值,完成应用内页面跳转逻辑。
- import { UIAbility, Want } from '@kit.AbilityKit';
- import { BusinessError } from '@kit.BasicServicesKit';
- import { hilog } from '@kit.PerformanceAnalysisKit';
- import { router, window } from '@kit.ArkUI';
-
- export default class EntryAbility extends UIAbility {
- private page: string = 'pages/Index';
- private uiContext?: UIContext;
-
- // 冷启动场景通过onCreate回调获取码值信息
- onCreate(want: Want): void {
- hilog.info(0x0001, '[Scan Access]', 'Succeeded in getting want in onCreate');
-
- // 从want中获取传入的链接信息。如传入的url为:https://www.example.com/scan
- this.getRouterUri(want);
- }
-
- // 热启动场景通过onNewWant回调获取码值信息
- onNewWant(want: Want): void {
- hilog.info(0x0001, '[Scan Access]', 'Succeeded in getting want in onNewWant');
- // 从want中获取传入的链接信息
- this.getRouterUri(want);
- }
-
- onWindowStageCreate(windowStage: window.WindowStage): void {
- hilog.info(0x0001, '[Scan Access]', 'Ability onWindowStageCreate');
- try {
- windowStage.getMainWindow().then((windowObj: window.Window) => {
- try {
- windowStage.loadContent(this.page).then(() => {
- hilog.info(0x0001, '[Scan Access]', 'Succeeded in loading the content.');
- try {
- this.uiContext = windowObj.getUIContext();
- hilog.info(0x0001, '[Scan Access]', 'Succeeded in getting UIContext.');
- } catch (err) {
- hilog.error(0x0001, '[Scan Access]', `Failed to get UIContext by windowObj. Code: ${err.code}.`);
- }
- }).catch((err: BusinessError) => {
- hilog.error(0x0001, '[Scan Access]', `Failed to load the content. Code: ${err.code}.`);
- })
- } catch (err) {
- hilog.error(0x0001, '[Scan Access]', `Failed to load the content. Code: ${err.code}.`);
- }
- }).catch((err: BusinessError) => {
- hilog.error(0x0001, '[Scan Access]', `Failed to get MainWindow. Code: ${err.code}.`);
- })
- } catch (err) {
- hilog.error(0x0001, '[Scan Access]', `Failed to get MainWindow. Code: ${err.code}.`);
- }
- }
-
- // 解析扫码结果,跳转相应页面
- private getRouterUri(want: Want): void {
- const uri: string | undefined = want?.uri;
- if (!uri) {
- return;
- }
- this.page = 'pages/Access';
-
- if (this.uiContext) {
- // 开发者根据解析的uri跳转至相应页面,例如需要跳转页面:pages/Access
- const status: router.RouterState = this.uiContext.getRouter().getState();
- if (status && status.name !== 'Access') {
- try {
- // 根据uri参数做业务处理
- this.uiContext.getRouter().pushUrl({
- url: 'pages/Access'
- }).catch((err: BusinessError) => {
- hilog.error(0x0001, '[Scan Access]', `Failed to pushUrl by getRouter. Code: ${err.code}.`);
- });
- } catch (err) {
- hilog.error(0x0001, '[Scan Access]', `Failed to pushUrl by getRouter. Code: ${err.code}.`);
- }
- }
- }
- }
- }
验证“扫码直达”服务。
集成效果,以美团单车场景为例:

集成扫码直达能力应用用户体验质量建议
应用完成开发后,可参照以下标准检查集成扫码直达后的用户体验是否符合预期:
| 标准编号 | 标准项名称 | 类型 | 标准详细描述 |
|---|---|---|---|
| 1 | 应用已安装跳转体验 | 规则 | 通过系统扫一扫扫描码图可以跳转到履约页面。履约页面指的是扫码后的目标服务页面,例如,扫支付码跳转到应用的支付页面,而非首页。 |
| 2 | 应用未安装跳转体验 | 建议 | 通过系统扫一扫扫描码图会拉起浏览器加载码值所对应的网页,请设计网页满足用户诉求、指导用户安装应用等。 |