This SDK allows you to create short links using the Short.io API based on a public API key and custom parameters. It also supports Android deep linking integration.
- Generate short links via Short.io API
- Customize short links using parameters
- Integrate Deeplinking in Android
- Simple and clean API for developers
You can integrate the SDK into your Android Studio project using JitPack
To install the SDK via JitPack:
To add the JitPack repository to your build file, Add it in your root settings.gradle
at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' } // Add this line
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") } // Add this line
}
}
Open App level build.gradle file build.gradle.kts (Module:app)
, Add the dependency:
It will be:
dependencies {
implementation("com.github.User:Repo:Tag") // Example
implementation("com.github.Short-io:android-sdk:v1.0.0") // Use this
}
Sync the Project with Gradle file, So the SDK can be Installed.
Import the SDK where it is needed by using:
import com.github.shortiosdk.ShortioSdk
-
Visit Short.io and sign up or log in to your account.
-
In the dashboard, navigate to Integrations & API.
-
Click CREATE API KEY button.
-
Enable the Public Key toggle.
-
Click CREATE to generate your API key.
import com.github.shortiosdk.ShortioSdk
import com.github.shortiosdk.ShortIOParameters
import com.github.shortiosdk.ShortIOResult
try {
val params = ShortIOParameters(
domain = "your_domain", // Replace with your Short.io domain
originalURL = "your_originalURL" // Replace with your Short.io domain
)
} catch (e: Exception) {
Log.e("ShortIO", "Error: ${e.message}", e)
}
Note: Both domain
and originalURL
are the required parameters. You can also pass optional parameters such as path
, title
, utmParameters
, etc.
val apiKey = "your_public_apiKey" // Replace with your Short.io Public API Key
thread {
try {
when (val result = ShortioSdk.shortenUrl(apiKey, params)) {
is ShortIOResult.Success -> {
println("Shortened URL: ${result.data.shortURL}")
}
is ShortIOResult.Error -> {
val error = result.data
println("Error ${error.statusCode}: ${error.message} (code: ${error.code})")
}
}
} catch (e: Exception) {
Log.e("ShortIO", "Error: ${e.message}", e)
}
}
The ShortIOParameters
struct is used to define the details of the short link you want to create. Below are the available parameters:
Parameter | Type | Required | Description |
---|---|---|---|
domain |
String |
β | Your Short.io domain (e.g., example.short.gy ) |
originalURL |
String |
β | The original URL to be shortened |
cloaking |
Boolean |
β | If true , hides the destination URL from the user |
password |
String |
β | Password to protect the short link |
redirectType |
Int |
β | Type of redirect (e.g., 301, 302) |
expiresAt |
StringOrInt |
β | Expiration timestamp in Unix format |
expiredURL |
String |
β | URL to redirect after expiration |
title |
String |
β | Custom title for the link |
tags |
[String] |
β | Tags to categorize the link |
utmSource |
String |
β | UTM source parameter |
utmMedium |
String |
β | UTM medium parameter |
utmCampaign |
String |
β | UTM campaign parameter |
utmTerm |
String |
β | UTM term parameter |
utmContent |
String |
β | UTM content parameter |
ttl |
StringOrInt |
β | Time to live for the short link |
path |
String |
β | Custom path for the short link |
androidURL |
String |
β | Fallback URL for Android |
iphoneURL |
String |
β | Fallback URL for iPhone |
createdAt |
StringOrInt |
β | Custom creation timestamp. |
clicksLimit |
Int |
β | Maximum number of clicks allowed |
passwordContact |
Boolean |
β | Whether contact details are required for password access |
skipQS |
Boolean |
β | If true , skips query string on redirect (default: false ) |
archived |
Boolean |
β | If true , archives the short link (default: false ) |
splitURL |
String |
β | URL for A/B testing |
splitPercent |
Int |
β | Split percentage for A/B testing |
integrationAdroll |
String |
β | AdRoll integration token |
integrationFB |
String |
β | Facebook Pixel ID |
integrationGA |
String |
β | Google Analytics ID |
integrationGTM |
String |
β | Google Tag Manager container ID |
folderId |
String |
β | ID of the folder where the link should be created |
To Import StringOrInt
type for specific parameters like expiresAt, ttl and createdAt:
import com.github.shortiosdk.StringOrInt
And to use it:
val params = ShortIOParametersModel(
// Example # 01
expiresAt = StringOrInt.IntVal(1) // OR
expiresAt = StringOrInt.Str("1")
// Example # 02
ttl = StringOrInt.Str("Hello") // OR
ttl = StringOrInt.IntVal(1)
// Example # 03
createdAt = StringOrInt.Str("Hello1234") //OR
createdAt = StringOrInt.IntVal(1)
)
To handle deep links via Short.io on Android, you'll need to set up Android App Links properly using your domain's Digital Asset Links and intent filters.
-
Open your Android project.
-
Navigate to android/app/src/main/AndroidManifest.xml.
-
Inside your MainActivity, add an intent filter to handle app links:
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="yourshortdomain.short.gy"
android:pathPrefix="/" />
</intent-filter>
</activity>
β Tip: Replace yourshortdomain.short.gy with your actual Short.io domain.
-
Go to Short.io.
-
Navigate to Domain Settings > Deep links for your selected domain.
-
In the Android Package Name field, enter your app's package name (e.g., com.example.app).
-
In the SHA-256 Certificate Fingerprint field, enter your release keyβs SHA-256 fingerprint.
// Example Package:
com.example.app
// Example SHA-256:
A1:B2:C3:D4:E5:F6:...:Z9
You can retrieve the fingerprint using the following command:
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
π Note: Use the SHA-256 of your release keystore for production builds.
- Click Save to update the Digital Asset Links.
-
Build and install your app on the device.
-
Go to App Settings > Open by Default.
-
Tap on βAdd linkβ under the Open by Default section.
-
Add your URL and make sure to enable the checkbox for your link.
-
Open a Notes, Email or messaging app on your device.
-
Tap a deep link (e.g., https://yourdomain.com/your-path).
-
If configured properly, your app will appear as an option to handle the link, or it will directly open the app.
-
Open your main activity file (e.g., MainActivity.kt).
-
Override the
onNewIntent()
method to receive new intents when the activity is already running:
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
handleIntent(intent)
}
- In the same activity, also handle the initial intent inside the
onCreate()
method:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
handleIntent(intent)
}
- Create the
handleIntent()
method to extract the URL:
private fun handleIntent(intent: Intent) {
val data: Uri? = intent.data
data?.let {
val url = it.toString()
Log.d("DeepLink", "App opened via URL: $url")
// Add your handling logic here
}
}
-
App is signed with the correct keystore.
-
The domain is verified on Short.io.
-
The intent-filter is added in AndroidManifest.xml.
-
App is installed from Play Store or via direct install (for testing with ADB).
Once these steps are complete, clicking a Short.io link (with your domain) will open the app directly if installed.