• Switch Language


  • Embed to Android App

    Add a Script Tag

    All you need to do to integrate Linkify into your application is to simply inject the script tag below into the HTML header of a web page.

    <script type="text/javascript"
      src="http://www-static.linkify.mobi/api/linkify.js?key=YOUR_API_KEY">
    </script>
    

    Example of WebView Application

    We will show an example of how to integrate Linkify into your Android WebView application. We will inject the JavaScript code to a web page (we will use Yahoo News! as an example).

    Add WebView

    To add a WebView into your application, simply include the <WebView> element in your activity layout that is placed in res/layout/activity_main.xml. The code below will add a WebView on your screen.

    <?xml version="1.0" encoding="utf-8"?>
    <WebView
      xmls:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/webview"
      android:layout_width="fill_parent"
      android:layout_width="fill_parent"
    />
    

    Allow Internet Access

    Since WebView requires Internet access, you will need to enable Internet access by adding the following codes in your manifest file, which is placed in AndroidManifest.xml.

    <manifest ... >
      <uses-permission android:name="android.permission.INTERNET"/>
    </manifest>

    Java Activity

    Here is an example of a Java Activity showing how to load the WebView and integrate Linkify. Before loading any web page, make an instance of WebView and enable the JavaScript. Then, set up the WebView client to integrate Linkify by injecting the JavaScript URL. Finally, load Yahoo! News.

    Notice that in the example below, we have loaded Linkify right after the application loaded. You may edit it to start Linkify by pressing some kind of button or any kind of actions.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
    
      final WebView webView = (WebView)findViewById(R.id.webView);
    
      WebSettings webSettings = webView.getSettings();
      webSettings.setJavascriptEnabled(true);
      webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
          view.loadUrl("javascript:(function() { " +
            "if (!window.linkifyLoaded) {" +
                "var d = document;" +
                "var s = d.createElement('script');" +
                "s.type = 'text/javascript';" +
                "s.src = 'http://www-static.linkify.mobi/api/linkify.js?key=YOUR_API_KEY';" +
                "d.getElementsByTagName('head')[0].appendChild(s);" +
                "window.linkifyLoaded = true;" +
            "}" +
          "})()");
        }
      });
      webView.loadUrl("http://news.yahoo.com");
    }
    

    Downloads

    Here is the code of the Android application that we have introduced above.

    Read the Docs v: latest
    Versions
    latest
    Downloads
    PDF
    HTML
    Epub
    On Read the Docs
    Project Home
    Builds

    Free document hosting provided by Read the Docs.