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
  • 11,166
  • 2
  • 35
  • 45
Bahaa Hany
  • 744
  • 13
  • 22
  • 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,548
  • 5
  • 43
  • 69
  • Now i created my link but when i click it first opens a webview of the url then opens the activity that takes less than a sec. is there a way to hide this. – Bahaa Hany Feb 24 '14 at 22:58
  • That's strange. Make sure you're returning `false` from `shouldOverrideUrlLoading`. – JiTHiN Feb 25 '14 at 06:12
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
  • 744
  • 13
  • 22