当前位置:网站首页>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
边栏推荐
- Basic data types and string types are converted to each other
- Merge sort and non comparison sort
- Learn how to compile basic components of rainbow from the source code
- Interface as a parameter (interface callback)
- AVL balanced binary search tree
- Deit learning notes
- [go ~ 0 to 1] obtain timestamp, time comparison, time format conversion, sleep and timer on the seventh day
- Virtual address space
- Go语言中,函数是一种类型
- [machine learning] watermelon book data set_ data sharing
猜你喜欢
One click installation of highly available Nacos clusters in rainbow
登山小分队(dfs)
Splunk query CSV lookup table data dynamic query
The single value view in Splunk uses to replace numeric values with text
Input of mathematical formula of obsidan
PVTV2--Pyramid Vision TransformerV2学习笔记
opencv学习笔记二——图像基本操作
如何在快应用中实现滑动操作组件
Automatic upgrading of database structure in rainbow
使用BiSeNet实现自己的数据集
随机推荐
Golan idea IntelliJ cannot input Chinese characters
Analyzing the influence of robot science and technology development concept on Social Research
ES6_ Arrow function
Go语言中,函数是一种类型
Using nocalhost to develop microservice application on rainbow
2-3 lookup tree
Bisenet features
Tuowei information uses the cloud native landing practice of rainbow
Openvscode cloud ide joins rainbow integrated development system
Teach you how to select PCB board by hand (II)
[Chongqing Guangdong education] organic electronics (Bilingual) reference materials of Nanjing University of Posts and Telecommunications
Implement your own dataset using bisenet
POJ - 3616 Milking Time(DP+LIS)
The truth of robot education in hands-on practice
PVTV2--Pyramid Vision TransformerV2学习笔记
Kotlin combines flatmap for filtering and zip merge operators
[untitled]
One click deployment of highly available emqx clusters in rainbow
Input of mathematical formula of obsidan
Low success rate of unit test report