Clicking on a link
<html>Click me to make a call</html>
in a WebView results in a "Page not found" error. Though the same link works just fine from the mobile browser. Any way to fix this?
EDIT:
String h = "<html>wtai</html>";
String g = "<html>tel</html>";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView web = (WebView) findViewById(R.id.webView1);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setPluginsEnabled(true);
web.loadData(h, "text/html", "utf-8");
}
This is the incorrect way of writing a tel WTAI link in Android.
Call us now!
is the correct way of writing this link.
Related
I am loading html5 game from Advance webview library. One game is working fine but other game gets stuck after clicking on play button.
I opened the same game on chrome & other browsers (in Android), its working fine there. So the problem is not with the game but with my code.
I have attached the code below. Please check and let me know what is the issue?
Java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
setContentView(R.layout.activity_game);
Intent intent = getIntent();
String url = intent.getStringExtra(Constants.INTENT_URL_KEY);
isItemPurchased = intent.getBooleanExtra(Constants.INTENT_ITEM_PURCHASED, false);
AdvancedWebView mWebView = findViewById(R.id.webView);
mWebView.setListener(this, this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebView.loadUrl(url);
}
I have a web page with a basic form (like a newsletter subscription).
The user sends its information and gets a success page with a link to the form submission page. If he doesn't click on the link the page will be automatically redirected after 5 seconds.
<meta http-equiv="refresh" content="5;url=www.site.com" />
So far so good! It works as expected in both desktop and mobile browsers.
Then I created an android app (min API SDK 21) with a web view to load the site.
The problem is that the auto refresh isn't working inside the web view...
Am I missing something? I'm trying to avoid the javascript hack...
Thanks for your time!
EDIT
I notice that when I click on the new form submission page link it opens the default browser instead of rendering it on the web view!
After searching for the problem, I came to a solution by resetting the URL on URL loading.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mWebView = findViewById(R.id.webview);
mWebView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
mWebView.loadUrl(url);
return true;
}
});
mWebView.loadUrl(url);
}
It's working, but I think it can be improved.
My initial problem was that I wasn't setting a WebViewClient.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mWebView = findViewById(R.id.webview);
mWebView.loadUrl(url);
}
Thus, I think I just need to add a WebViewClient and it'll work
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mWebView = findViewById(R.id.webview);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl(url);
}
Note, and if we want javascript to work we need to enable it
mWebView.getSettings().setJavaScriptEnabled(true);
I'm new with Android, so maybe someone can help me.
I have loaded an external URL in WebView.
I want that the links from my site http://www.domanin.com/about.php to open in WebView and the external link http://www.anotherdomanin.com/sample.php to open in default browser.
My code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyWeb = (WebView) findViewById(R.id.webView);
MyWeb.getSettings().setJavaScriptEnabled(true);
MyWeb.getSettings().setSaveFormData(true);
MyWeb.loadUrl("http://www.domanin.com");
}
In my android app the user can like my facebook page. Therefore I use a webview that loads a webpage that contains a facebook like box. The page is loaded well into the webview and then the following happens:
WebView loads my webpage with a facebook like box
By clicking on the Like button the user is redirected to the facebook login page
After login the user is redirect again back to my custom like page
But when clicking the like button the user is again redirected to the facebook login page
So I would expect, that the like is possible after logging in. It seems somehow as if the webview does not remember the login. Therefore, what do I have to do to repair this.
The following screenshot sequence shows what's happening:
I want to avoid using the facebook sdk for android! Especially this procedure works very good in my iphone version of the app.
Here is some code that is used to implement my desired functionality:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView fbWebView = (WebView) findViewById( R.id.facebookWebView );
fbWebView.getSettings().setJavaScriptEnabled(true);
fbWebView.setWebViewClient( new WebViewClient() {
#Override
public WebResourceResponse shouldInterceptRequest (WebView view, String url) {
Log.d("call url", url );
if ( url.contains("login.php?skip_api_login") ) {
fbWebView.loadUrl("http://www.example.de/iphone_facebook_like_page.html");
return null;
}
if( url.contains("user_successfully_liked") )
fbWebView.loadUrl("http://www.example-success.de");
return null;
}
});
fbWebView.loadUrl("http://www.example.de/iphone_facebook_like_page.html");
}
EDIT: I also tried the following to accept cookies but none of this worked
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().startSync();
CookieManager.setAcceptFileSchemeCookies(true);
CookieManager.getInstance().setAcceptCookie(true);
//rest is the same...
Overrding didn't work either
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
You have that error, because WebView isn't remembering cookies. Read that question on SO : WebView and Cookies on Android
Not sure if you've gotten an answer to your problem, but I tried a combination of these instructions and the code below, and that worked for me:
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
...
WebView webView = new WebView();
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(true);
settings.setDomStorageEnabled(true);
settings.setGeolocationEnabled(true); // this last one is probably optional
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(<your url here>);
...
}
You will then need to call the corresponding methods for the CookieSyncManager singleton class as outlined in the link above. Note that the sync class is deprecated in API Level 21: see details on CookieSyncManager class
I've created a WebView app and everything works fine.
I'm new to Android.The only remaining feature I need for the app is to hide the address bar. Because I want the app to look more like a regular app and not a webpage within a web browser window.
My code is like this,
package com.Mobi.ebookread;
public class Mobile extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final WebView webview = (WebView) findViewById(R.id.helloWebView);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.google.com");
}
}
How do I do it?
i think there is a problem. webview does not have an address bar, seems that the browser app is getting opened. It could be possible that there is a redirection happening and that causes the browser app to open up, and you did not intercept that redirect using a WebViewClient and shouldOverrideURLLoading()
Below is how the webview looks like.
Finally I Try with this. Its worked for me..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
//webview use to call own site
webview =(WebView)findViewById(R.id.webView1);
webview.setWebViewClient(new WebViewClient()); //use to hide the address bar
webview .getSettings().setJavaScriptEnabled(true);
webview .getSettings().setDomStorageEnabled(true); //to store history
webview.loadUrl("http://www.google.com");
}
and your entire main.xml(res/layout) look should like this:
`<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>`
don't go to add layouts.
try the following code:
webView=(WebView) findViewById(R.id.helloWebView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webview.loadUrl("http://www.google.com");