After a break in this COVID -19 lockdown, I have been working on an Android project that involves a Web URL preview UI, like Whatsapp and Facebook link preview. The main goal is to display the MetaData like Web Title, Description, Favicon, etc, of a given web address.
After some Googling, I come across a decent library to achieve the goal. This library for Android to load and preview the Web URL will enable your application to show Web Preview UI. Also, I encounter some problems with this library on Recyclerviews. So I just made some fixes and updated the library in GitHub. Let get into the point directly.
Link Preview – Web URL Preview Library
Link Preview – an Android library to load and show the HTTP/HTTPS URLs. To use this library your Android project do the following setup
Step 1:
Add this dependence in the project main Gradle file
Step 2:
Then include the following dependencies in application-level Gradle file
How to implement:
Setup the layout xml
Add the following lines in your XML layout to include the Link Previewer in your design. There are five different types of UI available in this library, you can include as per your need.
Plain URL Preview
Plain Preview is suitable for use in any theme of your application. Since there is no background color on link preview UI, this will be perfect for any UI designs.
Whatsapp URL Preview
This will give Whatsapp look-alike URL preview. To use this view add the following in your XML layout
Skype URL Preview
To get Skype like URL preview use include below lines in your XML files.
Telegram URL Preview
By adding the following codes into your XML view, you can get Telegram like URL preview in your Android design
Twitter URL Preview
Use these codes to get Twitter like URL preview or loader in your Android project
Code Implementation
Kotlin
Follow this to load the URL preview in Kotlin. get your view id and set the URL using theloadUrl()
method. Once the URL is get processed then the UI for preview the given web link will get updated.
Java
You can achieve this using Java as followed. Create a view reference to and ViewListener to load the URL.
Web Page Loading
This library is having an in-built function to handle click events, this will redirect you to the loaded Web URL.
Preview Of The Library
For more info and sample codes visit – Android Link Previewer