android集成
导入SDK
- 在project/build.gradle中的
buildscript
和allprojects
分别添加
buildscript {
repositories {
maven { url 'https://jfrog.baifu-tech.net/artifactory/android-tools/' }
}
}
allprojects {
repositories {
maven { url 'https://jfrog.baifu-tech.net/artifactory/android-tools/' }
}
}
- 在app/build.gradle中添加
android {
defaultConfig {
manifestPlaceholders = [
LINK_DEEP_APP_KEY : "项目配置的LINK_DEEP_APP_KEY",
LINK_DEEP_GROUP_SCHEME: "项目配置的LINK_DEEP_GROUP_SCHEME",
]
}
}
dependencies {
implementation 'com.linkdeep:linkdeep-core:1.0.18'
}
- 在AndroidManifest.xml中添加权限声明
<uses-permission android:name="android.permission.INTERNET"/>
- 在AndroidManifest.xml的
application
标签内设置AppKey
<meta-data
android:name="LINK_DEEP_APP_KEY"
android:value="${LINK_DEEP_APP_KEY}" />
- 在AndroidManifest.xml的唤醒页面
activity
标签中添加intent-filter
(一般为MainActivity
),配置scheme
,用于浏览器中拉起
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="${LINK_DEEP_APP_KEY}" />
<data android:scheme="${LINK_DEEP_GROUP_SCHEME}" />
</intent-filter>
备注:如果唤醒页面和启动页是同一Activity
,则AndroidManifest.xml的配置如下
<activity
android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="${LINK_DEEP_APP_KEY}" />
<data android:scheme="${LINK_DEEP_GROUP_SCHEME}" />
</intent-filter>
</activity>
使用 LinkDeep
- 实现
Application
,并在onCreate
中进行配置
@Override
public void onCreate() {
super.onCreate();
LinkDeep.INSTANCE.init(this);
}
- 并在AndroidManifest.xml注册
Application
<application
android:name="所实现的Application">
功能集成
- 一键拉起
在唤醒页面中,调用如下相关代码,获取web端传过来的动态参数
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinkDeep.INSTANCE.setAppWakeupListener(getAppWakeupListener());
}
@NotNull
private AppWakeupListener getAppWakeupListener() {
return new AppWakeupListener(getIntent()) {
@Override
public void onWakeup(@Nullable String wakeupData) {
}
};
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
LinkDeep.INSTANCE.setAppWakeupListener(getAppWakeupListener());
}
- 携带参数安装
在APP需要安装参数时(由web网页中传递过来的,如邀请码、游戏房间号等动态参数),调用LinkDeep.INSTANCE.setAppInstallListener方法,在回调中获取参数(可重复获取)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinkDeep.INSTANCE.setAppInstallListener(new AppInstallListener() {
@Override
public void onInstall(@Nullable String installData) {
}
});
}