Tik Tok Share Kit for Android

Tik Tok Share Kit for Android Documentation

Introduction

This Unity package lets you share your funny videos or pictures of your game directly to TikTok Android application.

Installation

Installation process

  • Download the package from Package Manager
  • Import it in your project
  • Download Google’s Unity Jar Resolver from: Unity Jar Resolver and import in your project. After that resolve all dependencies by using: Assets -> External Dependency Manager -> Android Resolver -> Resolve or Force Resolve
  • And that’s it, you can start coding!

Setup

Share

Sharing content using TikTok Share helper is easier than anything else, but before that there are a few things that needs to be done.

  • Open your main AndroidManifest.xml file in Assets/Plugins/Android/ folder and add this code inside tag:

      <provider
          android:name="androidx.core.content.FileProvider"
          android:authorities="com.package.name.fileprovider"
          android:exported="false"
          android:grantUriPermissions="true">
          <meta-data
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/file_paths"/>
      </provider>
    

Where com.package.name is the package name of your application.

  • Add this permission if it’s not already included in your AndroidManifest.xml file:

      <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    
  • Last but not least add <queries> tag inside your manifest file:

      <queries>
          <package android:name="com.zhiliaoapp.musically" />
      </queries>
    

Here is a sample AndroidManifest.xml file:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" android:installLocation="preferExternal" android:theme="@android:style/Theme.NoTitleBar" android:versionCode="1" android:versionName="1.0">
        <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
        <queries>
            <package android:name="com.zhiliaoapp.musically" />
        </queries>
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
            <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="orientation|screenSize">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
                <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
                <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
            </activity>
            <provider android:name="androidx.core.content.FileProvider" android:authorities="com.hardartcore.tiktokshare.fileprovider" android:exported="false" android:grantUriPermissions="true">
                <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"/>
            </provider>
        </application>
    </manifest>

And after the setup is complete you can use the helper class as:

    private void ShareTikTokImages() {
        // Use the instance to share images.
        TikTokShareHelper.ShareImages("Share message", string[]{imagepath}); // for images
    }

    private void ShareTikTokVideo() {
        // Use the instance to share images.
        TikTokShareHelper.ShareVideos("share message", string[]{videoPath}); // for videos
    }

Build Errors

If you encounter an issue: unexpected element <queries> found in <manifest> There is an easy fix for that: go to File -> Build Settings -> Player Settings -> Publishing Settings and select Custom Base Gradle Template. After that open the generated file baseProjectTemplate.gradle under Assets/Plugins/Android folder and change com.android.tools.build:gradle:*** to

Unity 2019.4+ -> com.android.tools.build:gradle:3.4.3
Unity 2021.3+ -> com.android.tools.build:gradle:4.0.1