当前位置:网站首页>How to integrate app linking services in harmonyos applications
How to integrate app linking services in harmonyos applications
2022-07-07 08:36:00 【Huawei Developer Forum】
brief introduction
App Linking It is a cross platform link that can work in the required way no matter whether the application has been installed or not , The target content of the link can be the product promotions you want to promote , It can also be the application native content that users can share with each other . You can create App Linking Then send the link address directly to the user , Or dynamically generated by the user in the application App Linking And share it with other users , Received App Linking After clicking the link, the user can jump to the content specified in the link .
When the user clicks App Linking when :
stay Harmony If the application has been installed on the platform , open App Linking It will jump directly to the native content of your application , If the application is not installed , It will guide the user to install the application and jump to the linked content .
Open in the desktop browser App Linking Will go to the same content on the website .
Configure the development environment
Opening App Linking
stay AppGallery Connect Page hits “ My project ”, In the application list of the project, select the application that needs to be opened App Linking Application , Navigation selection “ growth > App Linking”. If it's the first time App Linking service , Please click on “ Open now ” Opening service .

If the product data processing location is not set , You need to select the data processing location of the product , Please refer to Set the data processing location .
Integrate SDK
stay AppGallery Connect Page hits “ My project ”, In the application list of the project, select the application that needs to be opened App Linking Application .
Set up in the project “ routine ” Under tab , single click “ application ” Under column “agconnect-services.json” Download profile .
take “agconnect-services.json” Copy files to project entry Module directory .

open entry Under the module of build.gradle file , Add the following code integration App Linking SDK.
dependencies { ... implementation 'com.huawei.agconnect:agconnect-applinking-harmony:1.1.0.300' ... }Click... On the interface “Sync Now” Synchronize the completed configuration .
Interface design
This time Codelab In your DevEco Studio Create a layout page in the project , Refer to the following figure UI Design , With simple creation App Linking And share App Linking button .

The layout code is as follows :
<?xml version="1.0" encoding="utf-8"?> <DirectionalLayout xmlns:ohos="http://schemas.huawei.com/res/ohos" ohos:height="match_parent" ohos:width="match_parent" ohos:alignment="top" ohos:orientation="vertical"> <Text ohos:id="$+id:AppLinking" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:top_margin="100" ohos:text_size="80" ohos:left_margin="60" ohos:right_margin="60" ohos:multiple_lines="true" ohos:text="AppLinking" /> <Button ohos:id="$+id:createButton" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:top_margin="30vp" ohos:text_size="80" ohos:background_element="$graphic:background_ability_main" ohos:text="Create link" /> <Text ohos:height="match_content" ohos:width="match_content" ohos:left_margin="60" ohos:right_margin="60" ohos:multiple_lines="true" ohos:text_size="60" ohos:text="Short link" /> <Text ohos:id="$+id:shortlink" ohos:height="match_content" ohos:width="match_content" ohos:left_margin="60" ohos:right_margin="60" ohos:multiple_lines="true" ohos:text_size="40" /> <Text ohos:height="match_content" ohos:width="match_content" ohos:top_margin="20" ohos:left_margin="60" ohos:right_margin="60" ohos:multiple_lines="true" ohos:text_size="60" ohos:text="Long link" /> <Text ohos:id="$+id:longlink" ohos:height="match_content" ohos:width="match_content" ohos:top_margin="20" ohos:left_margin="60" ohos:right_margin="60" ohos:multiple_lines="true" ohos:text_size="40" /> <Button ohos:id="$+id:shareLongButton" ohos:height="match_content" ohos:width="match_content" ohos:top_margin="30vp" ohos:layout_alignment="horizontal_center" ohos:text_size="80" ohos:background_element="$graphic:background_ability_main" ohos:text="Share long link" /> <Button ohos:id="$+id:shareShortButton" ohos:height="match_content" ohos:width="match_content" ohos:top_margin="30vp" ohos:layout_alignment="horizontal_center" ohos:text_size="80" ohos:background_element="$graphic:background_ability_main" ohos:text="Share short link" /> </DirectionalLayout>Configure console link prefix
Sign in AppGallery Connect Website , Click on “ My project ”.
Find your project in the project list , Select your app from the list of apps under the project .
stay “ growth ” Found under column “App Linking”, choice “ Link prefix ” Tab , Click on “ Add link prefix ”, stay “ Set domain name ” Enter this Codelab The URL prefix used .

Finish typing and click “ next step ”, The system will automatically verify whether the link prefix is available .

Set the link prefix and DeepLink
Create in the application client App Linking when , You need to have the specified link prefix and DeepLink Address . This time Codelab We use the pre configured link prefix and DeepLink Address .
Development App Linking
1、 stay MainAbilitySlice Import related classes in .
import com.huawei.agconnect.applinking.AppLinking; import com.huawei.agconnect.applinking.ResourceTable; import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; import ohos.aafwk.content.Operation; import ohos.agp.components.Button; import ohos.agp.components.Component; import ohos.agp.components.Text; import ohos.hiviewdfx.HiLog; import ohos.hiviewdfx.HiLogLabel; import ohos.utils.net.Uri;2、 stay onStart Method to define related interface elements .
Button createButton = (Button) findComponentById(ResourceTable.Id_createButton); Button shareLongButton = (Button) findComponentById(ResourceTable.Id_shareLongButton); Button shareShortButton = (Button) findComponentById(ResourceTable.Id_shareShortButton); createButton.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { createLinking(); } }); shareLongButton.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { shareLink(longLink.getText()); } }); shareShortButton.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { shareLink(shortLink.getText()); } });3、 initialization App Linking Object instances .
AGConnectAppLinking.getInstance();4、 establish App Linking.
public void createLinking(){ AppLinking.Builder builder = AppLinking.newBuilder() .setIsShowPreview(true) .setUriPrefix(DOMAIN_URI_PREFIX) .setDeepLink(Uri.parse(DEEP_LINK)) .setHarmonyLinkInfo( AppLinking.HarmonyLinkInfo.newBuilder() .setHarmonyDeepLink("agckit://helloWorld") .build()) .setCampaignInfo( AppLinking.CampaignInfo.newBuilder() .setName("HDC") .setSource("Huawei") .setMedium("App") .build()) // Show preview page details .setPreviewType(AppLinking.LinkingPreviewType.SocialInfo) .setSocialCardInfo( AppLinking.SocialCardInfo.newBuilder() .setDescription("HDC") .setTitle("Huawei") .setImageUrl("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3862731350,3483076630&fm=26&gp=0.jpg") .build()); LongUri = builder.buildAppLinking().getUri().toString(); longLink.setText(LongUri); HiLog.info(hiLogLabel,"this is LongUri: " + LongUri); builder.buildShortAppLinking().addOnSuccessListener(shortAppLinking -> { ShortUri = shortAppLinking.getShortUrl().toString(); shortLink.setText(ShortUri); HiLog.info(hiLogLabel,"this is ShortLink: " + ShortUri); }).addOnFailureListener(e -> { }); }5、 Share created App Linking.
public void shareLink(String appLinking){ if (appLinking != null) { Intent intent = new Intent(); Operation operation = new Intent.OperationBuilder().withUri(Uri.parse(appLinking)).build(); intent.setOperation(operation); startAbility(intent); } }receive App Linking
1、 Receiving App Linking front , Need to be in HarmonyOS engineering config.json Add... To the configuration file Ability Of skills Field , Used to specify which App Linking. At present , Support use Deep Link To receive information , You need to deal with App Linking Of Ability Add the following configuration .
"skills": [ { "entities": [ "entity.system.home", "android.intent.action.VIEW" ], "actions": [ "action.system.home", "entity.system.default", "entity.system.browsable" ], "uris": [ { "scheme": "agckit", "host": "www.example.com" } ] } ]2、 When it is necessary to receive App Linking Of Ability Call in AGConnectAppLinking.getInstance() initialization AGConnectAppLinking example .
AGConnectAppLinking.getInstance() .getAppLinking(getAbility()) .addOnSuccessListener( resolvedLinkData -> { if(resolvedLinkData != null){ StringBuilder stringBuffer = new StringBuilder(); if(resolvedLinkData.getDeepLink() != null){ stringBuffer.append(resolvedLinkData.getDeepLink().toString()); // It is concluded that deeplink Then jump to the actual page Intent intents = new Intent(); intents.setUri(Uri.parse(resolvedLinkData.getDeepLink().toString())); startAbility(intents); } } }) .addOnFailureListener( e -> { AGCLogger.e("ApplinkingAbilitySlice", "getAppLinking:onFailure", e); });Package test
1、 stay DevEco Studio Click the run button on the , Run the application on your phone or Simulator . Click on “Create link”, You can see SDK Generated short links and long links .

2、 Click on “Share long link” Button , Share the link to your mobile browser , The browser will copy the long link and open the address , Load the configured App Linking Content . Click the open or download application button , You can jump to the application market to download , Explain that you passed SDK The generated link can open the corresponding application . The short link test method is also the same .

References
The details of the App Linking Please refer to App Linking Service Development Guide .
App Linking Correlation API Please see the API Reference resources .
Ben Codelab Used in Demo The download address of the source code is as follows Source download .
For more technical articles , Welcome to visit https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh
边栏推荐
- 基本数据类型和string类型互相转化
- One click deployment of highly available emqx clusters in rainbow
- How to realize the high temperature alarm of the machine room in the moving ring monitoring system
- Splunk query CSV lookup table data dynamic query
- 归并排序和非比较排序
- Kotlin combines flatmap for filtering and zip merge operators
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- POJ - 3616 Milking Time(DP+LIS)
- Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月6日-新手快速上手-可无缝升级tp6版本
- Implement your own dataset using bisenet
猜你喜欢

关于基于kangle和EP面板使用CDN

opencv学习笔记二——图像基本操作

One click installation of highly available Nacos clusters in rainbow

Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications

Openvscode cloud ide joins rainbow integrated development system

Golang compilation constraint / conditional compilation (/ / +build < tags>)

Bisenet features
![[paper reading] icml2020: can autonomous vehicles identify, recover from, and adapt to distribution shifts?](/img/ff/81a7b2ec08a6a422a5cf578c1fed13.jpg)
[paper reading] icml2020: can autonomous vehicles identify, recover from, and adapt to distribution shifts?

2-3 lookup tree

In go language, function is a type
随机推荐
[go ~ 0 to 1] obtain timestamp, time comparison, time format conversion, sleep and timer on the seventh day
SSM 整合
PVTV2--Pyramid Vision TransformerV2学习笔记
All about PDF crack, a complete solution to meet all your PDF needs
登山小分队(dfs)
How to understand distributed architecture and micro service architecture
使用AGC重签名服务前后渠道号信息异常分析
POJ - 3784 running medium
Lua programming learning notes
Virtual address space
Splunk查询csv lookup table数据动态查询
opencv学习笔记四——膨胀/腐蚀/开运算/闭运算
2-3 lookup tree
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月6日-新手快速上手-可无缝升级tp6版本
The truth of robot education in hands-on practice
[IELTS speaking] Anna's oral learning records part2
[IELTS speaking] Anna's oral learning records Part3
opencv学习笔记二——图像基本操作
GFS distributed file system
Standard function let and generic extension function in kotlin


