I am working on an Android project, and my task is to open a url in an embedded webview. Here is the code. When a button is clicked I open the url as follows:
yookosBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
linearLayout.setVisibility(View.GONE);
webview.setVisibility(View.VISIBLE);
webview.loadUrl("https://www.google.com.pk/");
}
});
1: When i open the google.com it is perfectly opened in embedded webview:
But when I replace the link with "http://videoshare.loveworldapis.com/commentredirect.php" url, the link is opened in full screen instead of embedded portion of webview as shown below:
Can you tell me what modification should I do to open the second website into embedded webview instead of full screen.
The WebView, by default, will open successive URLs by firing an intent, and opening the browser. To disable it so all URLs load in the WebView do this:
webView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
return false;
}
});
I suspect your web site load involves an HTTP redirect, and that redirect is causing the browser to open.
Related
I have a webview that looks like this
WebView webview = new WebView(this);
setContentView(webview);
webview.loadUrl("https://myurl.com/");
webview.setWebViewClient(new MyWebViewClient());
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Toast.makeText(LoginActivityWebView.this, url, Toast.LENGTH_SHORT).show();
return false;
}
}
When i change my URL to google everything works great, i can navigate to different sites and everything works.
When I put in my URl it is supposed to link to myurl2, but when I click it the toast prints myurl instead and the page juts reloads (not helpful!).
Any idea as to how this could happen and where shouldOverrideUrlLoading gets its url from?
If i load myurl in a browser and the user clicks a button then it works correctly.
If i load myurl in a webview, but open a browser on links pressed, then when the link is pressed it opens myurl on in a broswer and if you click the button again it correctly opens myurl2 (super weird).
Any ideas?
If the URL is opening in Chrome properly, you should consider adding, webView.getSettings().setJavaScriptEnabled(true) to your code and try again.
You can get the loaded URL from
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// do your stuff here
}
});
I want to create android application which will open url in same application as like facebook application without any browser.
I tried using WebView but it opens the url in browser.
You have to set up a webViewClient for your webView.
Sample code :
this.mWebView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
I am very new in App Development with Eclipse for android. I am able to make the buttons and links but am stuck at few places, and need help here.
The App has 3 button and a webview .
I am loading my Gmail account in webview by clicking the button . these buttonos are shortcuts like Inbox and Junk Box.So i should be able to check the mail by just clicking the inbox button.
The problems I face are:
When i click the inbox button for first time its ask for username and password but when i click login- It changes the webview Url to something else and ends with not found!! or error .I want to stop the Url from changing.
Webview Opens a new default webbrowser of my phone with the address bar on the top.
I want to hide that address bar and dont want to use the default browser to open the Page.
It has to be a smoth transaction without jumoing to URl page.
Hi Thank you for the response but i have few errors here,1) Since i am using three button , to activate the webview i have used the switch view ,therefore i am not able to define the above below is the sample code:
cancelbutton.setOnClickListener(new View.OnClickListener() {
private Activity result;
#SuppressWarnings("deprecation")
public void onClick(View v)
{
{ switch (v.getId())
{
case R.id.can_button3:
Intent myintent1 = new Intent
(Launcher.this,cancelbutton.class); Toast.makeText(Launcher.this, "Cancellation ",
Toast.LENGTH_SHORT).show();
setContentView(R.layout.activity_main);
WebView = (WebView) findViewById(R.id.webView1);
WebView.getSettings().setJavaScriptEnabled(true);
WebView.getSettings().setSavePassword(true);
WebView.loadUrl("https://gmail.com/inbox");break;
}
} }
}
);
junkBox.setOnClickListener(new View.OnClickListener() //Next Button{private Activity
result;
Create a CustomWebViewClient for your WebView. Override the following two functions:
shouldOverrideUrlLoading - To display the page within WebView
onReceivedSslError - To ignore SSL errors.
The code would look like this:
public class CustomWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed(); // Ignore SSL certificate errors
}
}
Add this WebViewClient to your WebView:
WebView webView = (WebView) result.findViewById(R.id.web_view);
webView.setWebViewClient(new CustomWebViewClient());
Below is the code which we are using to load the WebView. Capturing the url and redirecting to a new activity page is done using the “shouldOverrideUrlLoading”, once the user click on log in button in html page in the webview. But when loading the page, the page is redirecting after the security check(redirecting to https page) and control is coming to the “shouldOverrideUrlLoading” function and its making the activity blank. If we remove the “shouldOverrideUrlLoading” function we can see the log in screen on the WebView. But we are not able to go to the new activity. I tried to catch the redirection url and load it on the
“shouldOverrideUrlLoading” function, but its not allowing to load the content. And I try to return true and false for different conditions form “shouldOverrideUrlLoading” function that also not working.
Can anyone suggest what I need to do to load the log in page in the WebView after the redirecting from the security check and override the url after log in and redirect to a new activity?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_page);
WebView webview = (WebView) findViewById(R.id.wvLogin);
setContentView(webview);
webview.setWebViewClient(new WebViewClient()
{
// Override URL
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if(url.equals("http://Url which needs to override after login"))
{
Intent i = new Intent(getApplicationContext(), APImages.class);
startActivity(i);
}
return true;
}
});
webview.loadUrl("http://Login Page Url");
}
I am preparing sample app based on Web View. In my Splash screen have to load on url,if i click on splash screen it will open another site.It is working fine.But when i click on splash screen i want open separate browser.For that i have used following code,
this.webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
But it is opening same browser.Please Guide me.
view.loadUrl(url) will open the url in the same WebView. You have to define rule when to load in the same WebView or another seperate WebView or Browser. To load in seperate webview call anotherWebView.loadUrl(url). Or browser call with Intent.ACTION_VIEW.
The workaround could be like this-
if(need to load same webView)
{
view.loadUrl(url);
}
else if(need to load same webView)
{
anotherWebView.loadUrl(url);
}
else
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}