B4A Library Url Detector - detect and extract urls in a long piece of text

Discussion in 'Additional libraries, classes and official updates' started by tuhatinhvn, Aug 27, 2019.

  1. tuhatinhvn

    tuhatinhvn Active Member Licensed User

    This code is based on https://github.com/linkedin/URL-Detector
    First you need download 2 jar:


    And copy to your add-library folder
    And here code / function to extract list url from any text string

    #Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #End Region

    #Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
    #End Region
    Sub Process_Globals
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
    End Sub
    Sub Globals
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
        Dim str_input="Just because the.com heheyahoo.com weather is starting to get warm, does not mean that you should look sloppy. Get inspired and check out our collection of men's summer outfits.    famousoutfits    " As String
    Private NativeMe As JavaObject
    Dim s As List = NativeMe.RunMethod("url_detect"Array As String(str_input))

    For i=0 To s.Size-1
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub
    #IF JAVA
    import com.linkedin.urls.Url;
    import com.linkedin.urls.detection.UrlDetector;
    import com.linkedin.urls.detection.UrlDetectorOptions;
    import java.util.List;
    import java.util.ArrayList;
    public  List<String> url_detect(String stringinput){
            UrlDetector parser = new UrlDetector(stringinput, UrlDetectorOptions.Default);
            List<Url> found = parser.detect();
            List<String> itemsToAdd = new ArrayList<String>();
            for(Url url : found) {
            return itemsToAdd;
    #End If
    library can find and detect any urls such as:

    Last edited: Aug 27, 2019
    somed3v3loper, fredo, scsjc and 3 others like this.
  2. tuhatinhvn

    tuhatinhvn Active Member Licensed User

    Thank for your suggestion, library can find and detect any urls such as, so this exam string is too small to detect

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice