当前位置:网站首页>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
边栏推荐
- 23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP
- 打通法律服务群众“最后一公里”,方正璞华劳动人事法律自助咨询服务平台频获“点赞”
- Download and install orcale database11.2.0.4
- 2-3查找樹
- [untitled]
- Kotlin combines flatmap for filtering and zip merge operators
- Implementation of navigation bar at the bottom of applet
- [go ~ 0 to 1] obtain timestamp, time comparison, time format conversion, sleep and timer on the seventh day
- Golan idea IntelliJ cannot input Chinese characters
- Learn how to compile basic components of rainbow from the source code
猜你喜欢

SSM integration

AVL平衡二叉搜索树

如何在HarmonyOS应用中集成App Linking服务

Caractéristiques de bisenet

Using helm to install rainbow in various kubernetes

Input and output of floating point data (C language)

One click deployment of highly available emqx clusters in rainbow

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

南京商品房买卖启用电子合同,君子签助力房屋交易在线网签备案

The field value in Splunk subquery fuzzy matching CSV is*
随机推荐
National SMS center number inquiry
快速集成认证服务-HarmonyOS平台
IP-guard助力能源企业完善终端防泄密措施,保护机密资料安全
opencv学习笔记四——膨胀/腐蚀/开运算/闭运算
Deit learning notes
redis故障处理 “Can‘t save in background: fork: Cannot allocate memory“
Kotlin combines flatmap for filtering and zip merge operators
XCiT学习笔记
Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
Composer change domestic image
Using nocalhost to develop microservice application on rainbow
Download and install orcale database11.2.0.4
[Yu Yue education] C language programming reference of Zhongbei College of Nanjing Normal University
使用AGC重签名服务前后渠道号信息异常分析
Opencv learning note 4 - expansion / corrosion / open operation / close operation
打通法律服务群众“最后一公里”,方正璞华劳动人事法律自助咨询服务平台频获“点赞”
POJ - 3616 Milking Time(DP+LIS)
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
2-3查找树
2-3 lookup tree


