当前位置:网站首页>[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
边栏推荐
- js promise. all
- Win11 arm系统配置.net core环境变量
- 2022-06-17
- 二叉树专题--【深基16.例7】普通二叉树(简化版)(multiset 求前驱 后继 哨兵法)
- 从.bag文件中读取并保存.jpg图片和.pcd点云
- Overview of integrated learning
- HDU1236 排名(结构体排序)
- Introduction to MySQL 8 DBA foundation tutorial
- 华为AppLinking中统一链接的创建和使用
- Easyexcel, a concise, fast and memory saving excel processing tool
猜你喜欢
JSP webshell免殺——JSP的基礎
从MediaRecord录像中读取H264参数
[SUCTF2018]followme
Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
华为应用市场应用统计数据问题大揭秘
华为快应用中如何实现同时传递事件对象和自定义参数
简洁、快速、节约内存的Excel处理工具EasyExcel
V2X-Sim数据集(上海交大&纽约大学)
【AGC】构建服务3-认证服务示例
最详细MySql安装教程
随机推荐
Hdu1228 a + B (map mapping)
QT学习日记8——资源文件添加
全网显示 IP 归属地,是怎么实现的?
Easyexcel, a concise, fast and memory saving excel processing tool
Special topic of binary tree -- acwing 3384 Binary tree traversal (known preorder traversal, while building a tree, while outputting middle order traversal)
Leetcode+ 76 - 80 storm search topic
首份中国企业敏捷实践白皮书发布| 附完整下载
二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
大华设备播放过程中设置播放速度
二叉树专题--AcWing 3384. 二叉树遍历(已知先序遍历 边建树 边输出中序遍历)
华为快应用中如何实现同时传递事件对象和自定义参数
Luogu p4281 [ahoi2008] emergency gathering / gathering (tree doubling LCA)
UVM learning - build a simple UVM verification platform
PCL eigen introduction and simple use
【付费推广】常见问题合集,推荐榜单FAQ
从MediaRecord录像中读取H264参数
如何使用IDE自动签名调试鸿蒙应用
UVM factory mechanism
Special topic of binary tree -- acwing 3540 Binary search tree building (use the board to build a binary search tree and output the pre -, middle -, and post sequence traversal)
JSP webshell free -- the basis of JSP