open an "ACTION_VIEW" with intercepted POST headers - android

Following as reference this post
webview, download file on finish prepared document
I think of a possible solution, but as it is not the same doubt.
Them my possible solution as "intercept" POST header in concrete and redirect to intent.ACTION_VIEW
But can't find some example.
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}

Related

Android webview open external links in own application

When external links are clicked on my website, I want them to open in the application it is connected to. But I am getting page not found error. For example, when instagram.com is clicked, it will open on Instagram.
You need to define a webView CLient like this:
private class MyWebViewClient extends WebViewClient {
//link opener
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if ("yourHost.com".equals(Uri.parse(url).getHost()))
{
// This is my website, so do not override; let my WebView load the page
//loading.show();
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
on set this webViewClient in your webView like: mywebView.setWebViewClient(new MyWebViewClient())

How can i make a link to open in browser instead of WebView App

I created a WebView App and it's working fine but there is a link which I want it to open in the default browser instead of that app what can I do.
Add a WebViewClient to your webView (if not already added) and then override shouldOverrideUrlLoading () method:
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView webview, String url) {
if (url.contains(myUrl)) {
Intent intent= new Intent(Intent.ACTION_VIEW, myUrl);
context.startActivity(intent);
return true;
} else {
return super.shouldOverrideUrlLoading(webview, url);
}
}
}
This way your are telling your webview to not continue loading a specific url. Instead, launch the proper application (mostly a browser) to handle the url.

Android webview - how to skip url?

I have a webview with custom webview client. I'm intercepting requests with:
#Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
// ...
}
sometimes I'm getting informations about custom events from webview in a form of a link:
xyz://do-something
When it happens I want webview to ignore it. But 'shouldInterceptRequest' has to return something and when I'm returning 'null' instead of my page it shows: 'unknown url xyz://do-something'. How can I deal with that? How can I intercept the link but disable action on webview side?
You just need to do a string comparison from the site that you are in and the site that you want to go to.
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}

Android: unable to pass a url in webview

i am trying to pass a url which start with www.example.com/xxxxxxx in my webview it can be anything in the place of xxxxxxx. see the code you will understand
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("http://www.example.com"+"*")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
i want to pass any url from my website only else open it in default browser.
Uri.getHost() return the host from the authority, you should try to use if (Uri.parse(url).getHost().equals("www.example.com")) or if (Uri.parse(url).getHost().equals("example.com")).
Also, as a good practice, you should reverse your equals() statement like this: "example.com".equals(Uri.parse(url).getHost()) as you know that "example.com" will never be null and, as such, never throw a NullPointerException.

webview manual url redirection (manually set url's to show and skip)

Im using a webview to display a website.
The page iam opening using loadurl method is the login page,
on successful login redirection occurs to a particular page .
I want to skip that page i.e dont want to show that page rather show the webpage after that
eg If my webview starts with webpage A
on login success it shows webpage B
and then next page is webpage C
i want after Login success in page A it should go automatically to webpage C
current code im using
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url)
.getHost()
.equals("https://www.test.com")) {
web.loadUrl("https://www.test1.com");
}
return false;
}
so any tips/pointers as to how i do this?
thanks
Read this
You just need to do a string comparison from the site that you are in and the site that you want to go to.
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}

Categories

Resources