ShortIOApp is a sample Android project that demonstrates how to integrate and use the ShortIOSDK for generating short links and handling deep links using Short.io.
This project helps developers understand how to:
- Set up and use
ShortIOSDK
- Generate short URLs with customizable parameters
- Integrate and handle Deep Links
- MinSdk of Android project should be greater than or equal to 21
- A valid Short.io account
git clone https://github.com/Short-io/android-sdk-example
Open Android Studio, and open the android-sdk-example
folder in Android Studio.
Open the Main Activity file and replace the placeholder with your Short.io Public API Key:
val apiKey = "your_api_key"
Follow this guide in the ShortIOSDK README.
In your MainActivity file replace the placeholder with your Short.io domain and originalURL:
val params = ShortIOParameters(
domain = "your_domain", // e.g., example.short.gy
originalURL = "https://{your_domain}" // The destination URL
)
The app demonstrates:
Using your domain and original URL, you can generate a short link like this:
val apiKey = "your_api_key"
val params = ShortIOParameters(
domain = "your_domain", // e.g., example.short.gy
originalURL = "https://{your_domain}" // The destination URL
)
when (val result = ShortioSdk.shortenUrl(apiKey, params)) {
is ShortIOResult.Success -> {
val shortUrl = result.data.shortURL
Log.d("ShortIO", "Shortened URL: $shortUrl")
}
is ShortIOResult.Error -> {
val error = result.data
Log.e("ShortIO", "Error:- ${error.message}")
}
}
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" />
</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)
val result = ShortioSdk.handleIntent(intent)
Log.d("New Intent", "Host: ${result?.host}, Path: ${result?.path}")
}
- In the same activity, you can also handle the initial intent inside the
onCreate()
method:
// Optional
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val result = ShortioSdk.handleIntent(intent)
Log.d("New Intent", "Host: ${result?.host}, Path: ${result?.path}")
}
If you'd like to contribute to the SDK or sample app, please fork the repository and submit a pull request.