0

My app is about a book and im using webview to show text in the text there are specific words that i want to link them to other activity for example: "see page 125" i want the user to be able to click on page 125 & read this page in another activity.

Note: i must do it at runtime

Please any help is appreciated.

nikis
  • 10,991
  • 2
  • 33
  • 45
Bahaa Hany
  • 724
  • 12
  • 21
  • http://stackoverflow.com/questions/4066438/android-webview-how-to-handle-redirects-in-app-instead-of-opening-a-browser – JiTHiN Feb 22 '14 at 19:46
  • thanks rihan for your reply but this not what i need, i want to open activities how can i do this in the URL – Bahaa Hany Feb 24 '14 at 10:05
  • You can open activities inside `shouldOverrideUrlLoading` function. – JiTHiN Feb 24 '14 at 10:11

2 Answers2

2

Try this:

webview.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url){
      if(url.equalsIgnoreCase("page 125"))
       {
          //open your activity here
           return false;
       }

   }
});
JiTHiN
  • 6,450
  • 5
  • 40
  • 68
0

Here is the Code from the oncreate function

     introWv.setWebViewClient(new WebViewClient() 
    {
        public boolean shouldOverrideUrlLoading(WebView view, String url){

            //open your activity here
            bookID = Integer.parseInt((String) url.subSequence(0, 2));
            chapterNum = Integer.parseInt((String) url.subSequence(2, url.length()));
            Intent NT = new Intent(Intro.this, NTBible.class);
            SavePrefrences();
            startActivity(NT);
            Intro.this.finish();
            return false;

        }
    });

I load the data to the webview through introWv.loadDataWithBaseURL(null, introContent , "text/html", "utf-8", null);

Bahaa Hany
  • 724
  • 12
  • 21