当前位置:网站首页>[applinking practical case] share in app pictures through applinking
[applinking practical case] share in app pictures through applinking
2022-07-02 11:00:00 【Huawei Developer Forum】
Huawei AppGallery Connect Provided App Linking Service support , It can support cross platform sharing , Support in Android,iOS,Web And other platforms . about Android and iOS Mobile platform , You can directly pull up the specified page of the application , If the specified application is not installed on the device ,App Linking Links can also pull up stores to download apps , After downloading the app , You can also open the interface of the specified application for the first time .
Here's a , Through Huawei App Linking SDK, Scene sharing link , It is used to share the actual use scenarios of photos in the app .
Demand analysis
First, study Huawei App Linking Official documents : App Linking- Getting started
From the steps of official documents , Integrating Huawei App Linking service , It mainly involves four steps
- stay AGC Management desk , Create the corresponding AGC project .
- Create a specific link prefix in the project
- stay Android Integration in the project App Linking SDK, And create links flexibly through code
- To configure Android The application receives and processes App Linking link .
From the perspective of code requirements and configuration , Only the corresponding PhotoID, Downstream picture loading link , You can go through PhotoID Realize the recognition and loading of photos .
therefore , Just put PhotoID Add to App Linking The share of DeepLink in , Then when receiving , Through to DeepLink Parsing , To get the corresponding PhotoID.
Step1: establish AGC project
- stay AGC Console ,AppGallery Connect (huawei.com), Select my project in the interface .
- Select... On the interface + Number Add an item . Enter the corresponding project name .
- Add the corresponding application for the project , Here you need to configure the corresponding package name , Package name needs and Android Keep consistent in the project code .

Step2: Create a link prefix
- Under the project created in the previous step , Left menu bar , choice growth – App Linking, Enter into App Linking Tab .
- Click to use now , Open this service .
- Select “ Link prefix ” Tab , First add a link prefix , This prefix needs to be unique in the whole network , The system will automatically check your uniqueness .
For example, the link prefix I configured is as follows :

Step3: Integrate SDK、 Use API Create links
- go back to AGC Project Settings page , download agconnect-service.json file , Put it in Android Project App Under the path

2. open Android Project level gradle file , Add the following AGC Maven Warehouse address and AGCP plug-in unit .
buildscript {
repositories {
google()
jcenter()
maven { url 'http://developer.huawei.com/repo/' }
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath 'com.huawei.agconnect:agcp:1.6.0.300'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'http://developer.huawei.com/repo/' }
}
}
3. stay Android Application level gradle In file , application AGCP plug-in unit , And add App Linking SDK.
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
android{…}
dependencies {
….
implementation 'com.huawei.agconnect:agconnect-applinking:1.6.0.300'
}
4. Use API Interface , according to PhotoID Flexible creation App Linking link :
Note here , I introduced UserName and ImageURL Parameters , As a preview page when sharing , In addition, we will PhotoID This parameter is encapsulated in DeepLink in .
private static final String DOMAIN_URI_PREFIX = "https://photoplaza.drcn.agconnect.link";
private static final String DEEP_LINK = "https://photoplaza-agc.dra.agchosting.link";
private static final String SHARE_DEEP_LINK = "photo://photoplaza.share.com";
/**
* Call AppLinking.Builder to create a App Linking in App
*
* @param UserName input UserName
* @param PhotoID input PhotoID
* @param ImageUrl input ImageUrl
* @param icallback input icallback
*/
public void createShareLinking(String UserName, String PhotoID, String ImageUrl, Icallback icallback) {
String newDeep_Link = SHARE_DEEP_LINK + "?PhotoID=" + PhotoID;
AppLinking.Builder builder = AppLinking.newBuilder()
.setUriPrefix(DOMAIN_URI_PREFIX)
.setDeepLink(Uri.parse(DEEP_LINK))
.setAndroidLinkInfo(AppLinking.AndroidLinkInfo.newBuilder()
.setAndroidDeepLink(newDeep_Link)
.build())
.setSocialCardInfo(AppLinking.SocialCardInfo.newBuilder()
.setTitle("It is a beautiful Photo")
.setImageUrl(ImageUrl)
.setDescription(UserName + " share a Photo to you")
.build())
.setCampaignInfo(AppLinking.CampaignInfo.newBuilder()
.setName("UserSharePhoto")
.setSource("ShareInApp")
.setMedium("WeChat")
.build());
builder.buildShortAppLinking().addOnSuccessListener(shortAppLinking -> {
shortLink = shortAppLinking.getShortUrl().toString();
try {
icallback.onSuccess(shortLink, "Success");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}).addOnFailureListener(e -> icallback.onFailure(e.getMessage()));
}
Step4: receive App Linking Connect .
Let's talk about planning first , I plan on ImageDetailActivity This page , Conduct App Linking Link reception , in other words , Link directly after pulling up the application , It's this that opens Detail page .
- To configure AndroidManifest file . find ImageDetailActivity label , Add the need to receive DeepLink Of Intent-filter
<activity android:name=".ImageDetailActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ImageListActivity" />
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Add the customized domain name in the project here -->
<data android:host="photoplaza.share.com" android:scheme="photo" />
</intent-filter>
</activity>
2. open ImageDetail file , stay onCreate() Configure receive and parse App Linking And get DeepLink Related code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setDarkStatusIcon();
setContentView(R.layout.image_detail);
AGConnectAppLinking.getInstance().getAppLinking(ImageDetailActivity.this)
.addOnSuccessListener(resolvedLinkData -> {
// adopt AppLinking Start the application , Here is the restart of the installed scenario
if (resolvedLinkData!= null) {
Uri deepLink = resolvedLinkData.getDeepLink();
Log.i(TAG, "Open From AppLinking:" + deepLink);
// Get picture details.
getSharePicDetails(deepLink.toString());
}
}).addOnFailureListener(e->{
Bundle data = getIntent().getExtras();
if (data != null) {
if (data.getBoolean("firstLink")) {
// adopt AppLinking The entry to start the application for the first time
getSharePicDetails(data.getString("deepLink"));
}
else{
// Normal open ImageDetail page
initView();
}
}
});
}
/**
* Get a picture detail from a App Linking which share from other.
*
* @param link input a deepLink of App Linking
*/
private void getSharePicDetails(String link) {
ToastUtils.showToast(this, getResources().getString(R.string.loading_photo));
sharePhotoID = parseLink (link).get("PhotoID");
Log.i("AppLinking", "sharePhotoID: " + sharePhotoID);
}
/**
* Get param in received deepLink from AppLinking.
*
* @param url input the received deepLink
* @return myMap output the param
*/
public static Map<String, String> parseLink(String url) {
Map<String, String> myMap = new HashMap<String, String>();
String[] urlParts = url.split("\\?");
String[] params = urlParts[1].split("&");
for (String param : params) {
String[] keyValue = param.split("=");
myMap.put(keyValue[0], keyValue[1]);
}
return myMap;
}
Step5: Additional steps
because App Linking It will also be used in scenarios where the application is not installed . In this step, specific users are introduced to the scenario of new installation ,App Linking What kind of adaptation is needed .
- A description of the situation :
First, for applications that are not installed ,App Linking The link will be based on the specified package name ( The default is the one when creating the link App The package name ), According to the package name , Open the app download page of Huawei store of your mobile phone , Of course, you can also configure the local store to open .
After downloading and installing in the store , Click on the open ,App Linking It is also effective and can pass parameters . But because it is the first time to open , At this point, step 4 configures Intent-filter It doesn't work . Only the homepage of the application can be opened . Because the focus of this step , It's in the startup page of the application , adapter App Linking The scene opened for the first time .
2. Code adaptation , Open the app launch page , Same configuration getAppLinking Code for
For example, my startup page is LoginActivity,
AGConnectAppLinking.getInstance().getAppLinking(LoginActivity.this).addOnSuccessListener(resolvedLinkData -> {
// adopt AppLinking For the first time to start
Log.i(TAG,"StartUp From AppLinking");
if (resolvedLinkData!= null) {
String deepLink = resolvedLinkData.getDeepLink().toString();
Log.i("AppLinking", "deepLink:" + deepLink);
Bundle bundle = new Bundle();
bundle.putBoolean("firstLink", true);
bundle.putString("deepLink", deepLink);
Intent intent;
intent = new Intent(LoginActivity.this, ImageDetailActivity.class);
intent.putExtras(bundle);
startActivity(intent);
finish();
}
}).addOnFailureListener(e-> {
// Normal startup mode
Log.i(TAG,"Normal StartUp");
initView();
});
Summarize and sum up
above , Namely Android Within the project , adopt App Linking Of SDK, The ability to quickly build in app image sharing , There is no need to apply for an exclusive domain name , It also does not involve the operation and maintenance of the background 、H5 Page development 、JavaScript Code adaptation and so on , Easy five steps to complete . It can be said to be very convenient and fast .
The following is a screenshot of the simple steps of the page involved :

For more details , Please see the :
Huawei official website :
https://developer.huawei.com/consumer/cn/forum/topic/0202652719220650728?fid=0101271690375130218?ha_source=zzh
Reference documents
- Huawei AGC App Linking Service business introduction :App Linking- Business Introduction
- Huawei ACG Android Getting started with the platform :App Linking- Getting started
- Huawei AGC App Linking service , Troubleshooting common problems :App Linking- Video class : Troubleshooting common problems
边栏推荐
- 二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
- Special topic of binary tree -- [deep base 16. Example 7] ordinary binary tree (simplified version) (multiset seeks the precursor and subsequent sentry Art)
- Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
- 最详细MySql安装教程
- [SUCTF2018]followme
- Binary tree topic -- Luogu p3884 [jloi2009] binary tree problem (DFS for binary tree depth BFS for binary tree width Dijkstra for shortest path)
- 1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
- 【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
- UWA report uses tips. Did you get it? (the fourth bullet)
- 长投学堂上面的账户安全吗?
猜你喜欢

Analysis of hot spots in AI technology industry

Thanos Receiver

UVM learning - build a simple UVM verification platform

axis设备的rtsp setup头中的url不能带参

618 what is the secret of dominating the list again? Nike's latest financial report gives the answer

Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)

1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS

JSP webshell免殺——JSP的基礎

2022爱分析· 国央企数字化厂商全景报告
![[AI application] Hikvision ivms-4200 software installation](/img/4e/1640e3cafac13ce4d39520195c3217.png)
[AI application] Hikvision ivms-4200 software installation
随机推荐
力扣(LeetCode)182. 查找重复的电子邮箱(2022.07.01)
Common methods of JS array
简洁、快速、节约内存的Excel处理工具EasyExcel
Learn open62541 -- [66] UA_ Generation method of string
Open the encrypted SQLite method with sqlcipher
Easyexcel, a concise, fast and memory saving excel processing tool
二叉树专题--P1030 [NOIP2001 普及组] 求先序排列
华为AppLinking中统一链接的创建和使用
P1055 [noip2008 popularization group] ISBN number
[TS] 1368 seconds understand typescript generic tool types!
2022-06-17
HDU1234 开门人和关门人(水题)
【AI应用】海康威视iVMS-4200软件安装
【AppLinking实战案例】通过AppLinking分享应用内图片
JVM garbage collector
Mysql database remote access permission settings
Binary tree topic -- Luogu p3884 [jloi2009] binary tree problem (DFS for binary tree depth BFS for binary tree width Dijkstra for shortest path)
如何用list组件实现tabbar标题栏
MySQL lethal serial question 3 -- are you familiar with MySQL locks?
Nodejs+express+mysql simple blog building