当前位置:网站首页>Share pictures or link to Tiktok
Share pictures or link to Tiktok
2022-07-21 19:54:00 【mr_ sunming】
Catalog
The second step : Integration into the development environment
1. The root directory build.gradle Import and stock in
2.app moudel Under the table of contents build.gradle Import and stock in
3. Configure the package visibility of Tiktok
Use one :Android- Share with Tiktok friends or Group
Use two :android Share picture support fileprovider The way
Preface
This article is only used to record relevant configurations
One 、 Official documents
Two 、 Start configuration
SDK The minimum support :Android API 15 - 4.0.x edition
SDK Access currently requires the introduction of two dependent packages , Include opensdk-china-external
and opensdk-common
, For convenience , Both use the same version number . The latest version is 0.1.9.0.
First step : Apply to Tiktok short video for your clientkey And related authorities
succeed in inviting sb. Developer application registration page To apply for , You will get clientkey, After through clientkey Apply for relevant permissions for the application , Such as sharing 、 to grant authorization 、 Default topic, etc ; Relevant functions can be used after approval ;
The second step : Integration into the development environment
1. The root directory build.gradle Import and stock in
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
// Tiktok
maven { url 'https://artifact.bytedance.com/repository/AwemeOpenSDK' }
maven { url "https://maven.byted.org/repository/android_public/" }
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.2"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
// Tiktok
maven { url 'https://artifact.bytedance.com/repository/AwemeOpenSDK' }
maven { url "https://maven.byted.org/repository/android_public/" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2.app moudel Under the table of contents build.gradle Import and stock in
// Tiktok platform access
implementation 'com.bytedance.ies.ugc.aweme:opensdk-china-external:0.1.9.0'
implementation 'com.bytedance.ies.ugc.aweme:opensdk-common:0.1.9.0'
3. Configure the package visibility of Tiktok
Android 11 In order to strengthen the privacy protection strategy , Introduced many changes and restrictions , Where package visibility change , It will lead to third-party applications through the open platform of Tiktok SDK Can't pull up Tiktok normally , Therefore, it is impossible to use all the functions of the open platform , Including but not limited to sharing messages to Tiktok 、 Log in to your account through Tiktok .
One thing in particular to note ,Android11 This change will only affect the upgrade <strong>targetSdkVersion=30</strong> Application , Applications that have not been upgraded will not be affected .
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package=" Your bag name ">
<queries>
<!-- It allows you to query the package information of Tiktok and Tiktok express -->
<package android:name="com.ss.android.ugc.aweme" />
<package android:name="com.ss.android.ugc.aweme.lite" />
</queries>
</manifest>
Use one :Android- Share with Tiktok friends or Group
Apply to Tiktok short video for your clientkey And relevant permissions, please apply on the developer application registration page , You will get clientkey, After through clientkey Apply for relevant permissions for the application , Such as sharing with Tiktok contact / Group (im.share) etc. ; Relevant functions can be used after approval ;
- initialization stay Application in , initialization DouYinOpenApiFactory
// It is modified to apply on the developer application registration page clientkey
DouYinOpenApiFactory.init(new DouYinOpenConfig("[Client Key]"));
2. - Manifest Apply for permission in , Register receive callback activity
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
// If the third party has customized the method of receiving callbacks activity You can skip this step
<activity
android:name=".douyinapi.DouYinEntryActivity"
android:launchMode="singleTask"
android:taskAffinity=" Your bag name "
android:exported="true">
</activity>
3. Share html ( Be careful : If you want to share html Link to Tiktok contact , Please go to your application in the official website management center first im.share Add permission to share links for page link verification , To share successfully .)
val douyinOpenApi = DouYinOpenApiFactory.create(activity)
// Tiktok sharing html
val request = ShareToContact.Request().apply {
htmlObject = ContactHtmlObject().apply {
html = "https://www.baidu.com/" // Yours html link ( Required )
discription = " Baidu " // Yours html describe ( Required )
title = “App Name” // Yours html title( Required )
//thumbUrl // Yours html Cover map of ( Remote picture ) ( optional , If not , Then use the icon uploaded when applying on the official website of the open platform )
}
}
// Call up sharing
if (douyinOpenApi.isAppSupportShareToContacts) {
douyinOpenApi.shareToContacts(request)
} else {
showToast(R.string.tiktok_version_not_support)
}
4. Receive callback activity
/**
* Description Accept the return information
* Version 1.0
*/
public class DouYinEntryActivity extends Activity implements IApiEventHandler {
DouYinOpenApi douYinOpenApi;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
douYinOpenApi = DouYinOpenApiFactory.create(this);
douYinOpenApi.handleIntent(getIntent(), this);
}
@Override
public void onReq(BaseReq req) {
}
@Override
public void onResp(BaseResp resp) {
if (resp instanceof ShareToContact.Response) {
switch (resp.errorCode) {
case 20000:
//TODO Share success
break;
case 20013:
//TODO Cancel sharing
break;
default:
//TODO Sharing failure
break;
}
finish();
}
}
@Override
public void onErrorIntent(@Nullable Intent intent) {
//TODO Sharing failure
}
}
5. confusion
-keep class com.bytedance.sdk.open.aweme.**
Be careful , If there is confusion in the code of your application , Hang up Tiktok IM After sharing , Can't get IM Callback of sharing results , Please send your received callback activity(DouYinEntryActivity Or your customized callback activity) Also add the no confusion list
Use two :android Share picture support fileprovider The way
The main purpose is to adapt Android11
1. To configure
In the project AndroidManifest.xml Add related configuration
<!--${applicationId} Name your app package -->
<provider android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
stay res/xml Catalog ( without xml Catalog , Then create a new one ) Next , Add files file_provider_paths.xml
, The contents are as follows :
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="sharedata" path="shareData/"/>
</paths>
2. Use FileProvider Interface to share pictures
fun shareToDouYin(activity: Activity, bitmap: Bitmap) {
// Create a shared data file
val pathDir = activity.getExternalFilesDir("shareData")!!.path
val filePath = "$pathDir/share.jpg"
// Storage
val saveSuccess = save(bitmap, File(filePath), Bitmap.CompressFormat.JPEG, false)
if (saveSuccess) {
val fileUri = getFileUri(activity.applicationContext, filePath)
// Share a single picture / More pictures
val douyinOpenApi = DouYinOpenApiFactory.create(activity)
val request = ShareToContact.Request().apply {
mMediaContent = MediaContent().apply {
mMediaObject = ImageObject().apply {
mImagePaths = arrayListOf(fileUri)
}
}
}
// Determine whether you can share with your contacts
if (douyinOpenApi.isAppSupportShareToContacts) {
douyinOpenApi.shareToContacts(request);
} else {
Toast.makeText(activity, " The current Tiktok version does not support ", Toast.LENGTH_SHORT).show()
}
} else {
Toast.makeText(activity, " Sharing failure ", Toast.LENGTH_SHORT).show()
}
}
/**
* Save the bitmap.
*
* @param src The source of bitmap.
* @param file The file.
* @param format The format of the image.
* @param recycle True to recycle the source of bitmap, false otherwise.
* @return `true`: success<br></br>`false`: fail
*/
fun save(src: Bitmap, file: File, format: CompressFormat, recycle: Boolean): Boolean {
var os: OutputStream? = null
var ret = false
try {
os = BufferedOutputStream(FileOutputStream(file))
ret = src.compress(format, 100, os)
if (recycle && !src.isRecycled) src.recycle()
} catch (e: IOException) {
e.printStackTrace()
} finally {
try {
os?.close()
} catch (e: IOException) {
e.printStackTrace()
}
}
return ret
}
fun getFileUri(context: Context, filePath: String): String {
// The filePath Corresponding to xml/file_provider_paths The first line of the configuration :, So it can be shared
val file = File(filePath)
// To work with `AndroidManifest.xml` Internally configured `authorities` Agreement
val contentUri: Uri = FileProvider.getUriForFile(
context,
context.packageName + ".fileprovider",
file
)
// Authorize Tiktok access path , Fill in the name of Tiktok bag here
context.grantUriPermission(
"com.ss.android.ugc.aweme",
contentUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
)
// Use contentPath Share as a file path contentUri.toString() That is to say "content://" The first path for sharing
return contentUri.toString()
}
summary
The document of Tiktok is still very clear , Finally, the complete list file looks like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package=" Your bag name ">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<queries>
<!-- It allows you to query the package information of Tiktok and Tiktok express -->
<package android:name="com.ss.android.ugc.aweme" />
<package android:name="com.ss.android.ugc.aweme.lite" />
</queries>
<application>
<!-- Tiktok sharing results page -->
<activity
android:name=".douyinapi.DouYinEntryActivity"
android:exported="true"
android:launchMode="singleTask"
android:taskAffinity="${applicationId}" />
<provider android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
<!--${applicationId} Name your app package -->
<!-- endregion-->
</application>
</manifest>
边栏推荐
- (3) Jdbctemplate
- 426. 将二叉搜索树转化为排序的双向链表
- Typescript basic learning notes
- STM32——定位模块ATGM336H,数据解析,提取经纬度
- The ability to detect movement in vivo and build a safe and reliable payment level "face brushing" experience
- Attack and defense world ----- lottery
- 基于hydra库实现yaml配置文件的读取(支持命令行参数)
- 项目管理成熟度模型及项目量化管理
- The command of gun compiler is g++:$g++ -o prog1 prog1 cc
- GUN编译器的命令是g++:$ g++ -o prog1 prog1.cc
猜你喜欢
iwemeta:史玉柱的黄金酱酒:贴牌的代工厂都被关停了,谁在生产?
Written test compulsory training day 18
jimu积木报表打印时多一页空白页-问题解决
The ability to detect movement in vivo and build a safe and reliable payment level "face brushing" experience
ECCV 2022 open source | target segmentation for 10000 frames of video
CV (4)- Backpropagation and Neural Networks
PWM output experiment
Gradle项目构建工具入门
元宇宙iwemeta:风口上的脑机接口,偷偷的解密大脑
Electromagnetic field and electromagnetic wave experiment II familiar with the application of MATLAB PDETOOL in two-dimensional electromagnetic problems
随机推荐
Audience analysis and uninstall analysis have been comprehensively upgraded, and HMS core analysis service version 6.6.0 has been updated
从平面设计转行软件测试,喜提11K+13薪,回头看看我很幸运
input: dynamic input is missing dimensions in profile
ECCV 2022 open source | target segmentation for 10000 frames of video
Assertion failed: inputs.at(2).is_weights
Importerror: DLL load failed while importing win32gui: the specified module cannot be found.
Support vector machine (understanding, derivation, MATLAB examples)
STM32——ADC读取光敏传感器控制LED灯,看门狗中断
"New product release" B2B connector version NXP i.MX 8m Mini industrial core board
Remove unnecessary fields
Assertion failed: inputs. at(2). is_ weights
ctfshow MengXIn misc1
The command of gun compiler is g++:$g++ -o prog1 prog1 cc
Download Yotube videos using clip converter website
2022.7.21DAY611
元宇宙iwemeta:风口上的脑机接口,偷偷的解密大脑
Unity ECS 测试Demo
Machine learning sklearn dataset
Internal implementation principle of sort
Get IP address