当前位置:网站首页>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
边栏推荐
- 2-3查找樹
- 23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP
- opencv学习笔记三——图像平滑/去噪处理
- 2-3 lookup tree
- The reified keyword in kotlin is used for generics
- Interpreting the practical application of maker thinking and mathematics curriculum
- One click installation of highly available Nacos clusters in rainbow
- Download and install orcale database11.2.0.4
- XCiT学习笔记
- Exercise arrangement 2.10, 11
猜你喜欢

Deit learning notes

PLSQL的安装和配置

opencv学习笔记五——梯度计算/边缘检测
![[untitled]](/img/b5/348b1d8b5d34cf10e715522b9871f2.png)
[untitled]

GFS distributed file system

All about PDF crack, a complete solution to meet all your PDF needs

Obsidan之数学公式的输入

Using nocalhost to develop microservice application on rainbow

Input and output of floating point data (C language)

Splunk查询csv lookup table数据动态查询
随机推荐
GFS分布式文件系统
Automatic upgrading of database structure in rainbow
Obsidan之数学公式的输入
Open3D ISS关键点
Practice of implementing cloud native Devops based on rainbow library app
【无标题】
rsync远程同步
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University
23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP
[IELTS speaking] Anna's oral learning records Part3
[Chongqing Guangdong education] accounting reference materials of Nanjing University of Information Engineering
The truth of robot education in hands-on practice
opencv学习笔记四——膨胀/腐蚀/开运算/闭运算
字符串操作
Exercise arrangement 2.10, 11
[machine learning] watermelon book data set_ data sharing
DeiT学习笔记
如何在快应用中实现滑动操作组件
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
Thirteen forms of lambda in kotlin


