=================================
It makes a preview from an url, grabbing all the information such as title, relevant texts and images.
Note : Modified project of @LeonardoCardoso/Android-Link-Preview to add support of androidx and latest gradle updates.
- jsoup is a smart lib to get the html code.
Simply add the repository to your build.gradle file:
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}And you can use the artifacts like this:
dependencies {
implementation 'com.github.avinashcoder:Android-Link-Preview:1.0.0'
// ...
}If you use ProGuard, it is advised that you keep the jsoup dependencies by adding
-keeppackagenames org.jsoup.nodesto your ProGuard rules file.
import com.coder.link.preview.library.TextCrawler;
// ...
// Create an instance of the TextCrawler to parse your url into a preview.
TextCrawler textCrawler = new TextCrawler();
// ..
// Create the callbacks to handle pre and post exicution of the preview generation.
LinkPreviewCallback linkPreviewCallback = new LinkPreviewCallback() {
@Override
public void onPre() {
// Any work that needs to be done before generating the preview. Usually inflate
// your custom preview layout here.
}
@Override
public void onPos(SourceContent sourceContent, boolean b) {
// Populate your preview layout with the results of sourceContent.
}
};textCrawler.makePreview( linkPreviewCallback, url);If you are using Android Link Preview inside of an Activity, it is important to cancel unfinished Preview activites at the end of the Activity's lifecycle.
@Override
protected void onDestroy() {
super.onDestroy();
textCrawler.cancel();
}Developed by @Avinash Coder.
