Webview - open links in external apps and browsers / android

Stumpp

I am a beginner in making android applications. I have made a web application in HTML which i want to be able to use in my application that I am making in android studio. I managed to make a simple web view in android studio which makes my web application work fine when i test it on my device. The only problem is that the web view handles all the URL´s inside my web application. The web application consists of tabs that directs me to different pages when i click on them which is what i want. But I have contact-buttons and different links that i want to be "released" from the web view. Lets take the contact button as an example. I have a Galaxy note which I am using to test my apps. When i open my application on my phone i see my Web application and i can navigate around. When i click the contact button, the web view handles the link and gives me a "page could not load" instead of opening the mail application on my phone. I also have buttons with links that I want to be able to open in an external browser on my phone. I hope you understand my problem and I am sorry for my bad english.

This is some of my code for the web view.

Mainactivity.java

public class MainActivity extends ActionBarActivity {

WebView browser;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    browser = (WebView) findViewById(R.id.wvwMain);

    browser.getSettings().setJavaScriptEnabled(true);
    browser.getSettings().setLoadWithOverviewMode(true);
    browser.getSettings().setUseWideViewPort(true);

    browser.setWebViewClient(new ourViewClient());
    try {
        browser.loadUrl("http://WebAppURL");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

OurViewClient.java

public class ourViewClient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);

    return true; 
 }    
}
M D

Try this way implement your WebViewClient like

 private class VideoWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            try{
                System.out.println("url called:::" + url);
                if (url.startsWith("tel:")) {
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                    startActivity(intent);
                }  else if (url.startsWith("http:")
                        || url.startsWith("https:")) {

                     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
                     startActivity(intent);

                }  else if (url.startsWith("mailto:")) {

                    MailTo mt=MailTo.parse(url);

                    send_email(mt.getTo());

                }
                else {
                    return false;
                }
            }catch(Exception e){
                e.printStackTrace();
            }

            return true;
        }

    }

and create send mail function like

   public void send_email(String email_add) {
    System.out.println("Email address::::" + email_add);

    final Intent emailIntent = new Intent(
            android.content.Intent.ACTION_SEND);
    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
            new String[] { email_add });
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
    yourActivity.this.startActivity(
            Intent.createChooser(emailIntent, "Send mail..."));

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Handling external links in android webview

From Dev

Android webview not displaying html with external js links

From Dev

Preventing iOS mobile browsers from forcing open apps when clicking links?

From Dev

Open external browser in webview?

From Dev

Android WebView links to same window with target=_blank to open new window

From Dev

Open external links in Phonegap Build App (iOS/Android)

From Dev

Open external links in Phonegap Build App (iOS/Android)

From Dev

SwipeRefreshLayout and to handle external links in webview( manual class) not working together in android webview

From Dev

MacOS/OSX Webview not opening external links

From Dev

Android open URL in WebView

From Dev

Android webview: download files like browsers do

From Dev

how to properly open google play links on html page in android webview with setWebViewClient?

From Dev

Open links in safari instead of inside webview

From Dev

Open links in safari instead of inside webview

From Dev

Links from apps always open a file:// URL

From Dev

WKWebView won't open external links

From Dev

I want external links to open in my browser

From Dev

Open all external links in new window

From Dev

Open PDF links in external application on Chrome

From Dev

Open Youtube links in external videoplayer from browser

From Dev

How to open external links in another tab?

From Dev

Is it possible to set different browsers to open links based on the application that opens them?

From Dev

Open external apps and web pages in ZK

From Dev

CTRL+Clicking commented URLs and open in external browsers

From Dev

webView in android open the website in web instead of webview

From Java

open the link in webview Android Studio

From Dev

Android Webview - open my browser

From Dev

Android WebView open Https website

From Dev

Website won't load in android webview but works fine in android browsers

Related Related

  1. 1

    Handling external links in android webview

  2. 2

    Android webview not displaying html with external js links

  3. 3

    Preventing iOS mobile browsers from forcing open apps when clicking links?

  4. 4

    Open external browser in webview?

  5. 5

    Android WebView links to same window with target=_blank to open new window

  6. 6

    Open external links in Phonegap Build App (iOS/Android)

  7. 7

    Open external links in Phonegap Build App (iOS/Android)

  8. 8

    SwipeRefreshLayout and to handle external links in webview( manual class) not working together in android webview

  9. 9

    MacOS/OSX Webview not opening external links

  10. 10

    Android open URL in WebView

  11. 11

    Android webview: download files like browsers do

  12. 12

    how to properly open google play links on html page in android webview with setWebViewClient?

  13. 13

    Open links in safari instead of inside webview

  14. 14

    Open links in safari instead of inside webview

  15. 15

    Links from apps always open a file:// URL

  16. 16

    WKWebView won't open external links

  17. 17

    I want external links to open in my browser

  18. 18

    Open all external links in new window

  19. 19

    Open PDF links in external application on Chrome

  20. 20

    Open Youtube links in external videoplayer from browser

  21. 21

    How to open external links in another tab?

  22. 22

    Is it possible to set different browsers to open links based on the application that opens them?

  23. 23

    Open external apps and web pages in ZK

  24. 24

    CTRL+Clicking commented URLs and open in external browsers

  25. 25

    webView in android open the website in web instead of webview

  26. 26

    open the link in webview Android Studio

  27. 27

    Android Webview - open my browser

  28. 28

    Android WebView open Https website

  29. 29

    Website won't load in android webview but works fine in android browsers

HotTag

Archive