Android Link Preview is a lightweight and easy-to-use library for generating link previews in Android applications. It extracts metadata such as title, description, and image from a provided URL and presents them in a formatted preview component.
- Extracts metadata including title, description, and image from any URL.
- Supports preview generation for webpages, videos, and profiles.
- Handles redirects and partial downloads using OkHttp.
- Ignores restricted platforms based on regional settings (e.g., platforms banned in India).
In your root settings.gradle
file, add the JitPack repository:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
In your module-level build.gradle
file, add the following dependency:
dependencies {
implementation 'com.github.vishalkumarsinghvi:Android-Link-Preview:1.1'
}
Replace Tag
with the latest release tag from the Releases.
To generate a link preview, simply pass the URL to the LinkPreviewGenerator
:
import com.vishalkumarsinghvi.linkpreview.LinkPreviewGenerator
import com.vishalkumarsinghvi.linkpreview.model.LinkPreviewData
data class LinkPreviewData(
val title: String? = null,
val description: String? = null,
val imageUrl: String? = null,
val url: String? = null,
@LinkPreviewType val linkContentType: Int = LinkPreviewType.WEBPAGE,
)
fun generateLinkPreview(url: String) {
val previewData: LinkPreviewData? = LinkMetadataParser.parse(url)
previewData?.let {
println("Title: ${it.title}")
println("Description: ${it.description}")
println("Image URL: ${it.imageUrl}")
println("Web URL: ${it.url}")
println("Link type: ${it.linkContentType}") // 0 -> webpage , 1-> profile (FB,insta) , 2-> Video
}
}
- Customize request headers
- Handle restricted platforms
- Optimize metadata extraction
Refer to the Wiki for advanced usage and configuration.
This library is licensed under the MIT License. See the LICENSE file for more information.