I am integrating html page in webview and in that i need to scan the credit card.
But, in my android device version 10, "Scan new card" option is not visible.
In android 8, this option is visible but Card holder name is not coming.
So anyone have any idea about the same?
Below is the activity code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new MyWebViewClient());
// REMOTE RESOURCE
mWebView.loadUrl("https://hostedhtml/");
}
Below is the html code:
<form action="freedomofkeima://?ThisIsResponseSample" method="get">
<label for="nameoncard">Name on Card</label>
<input autocomplete="cc-name" id="nameoncard" name="nameoncard" type="text">
<label for="ccnumber">Credit Card Number</label>
<input autocomplete="cc-number" id="ccnumber" name="ccnumber" type="text">
<label for="cc-exp-month">Expiration Month</label>
<input autocomplete="cc-exp-month" id="cc-exp-month" name="cc-exp-month" type="text">
<label for="cc-exp-year">Expiration Year</label>
<input autocomplete="cc-exp-year" id="cc-exp-year" name="cc-exp-year" type="text">
<input name="submit" type="submit" value="Submit">
</form>
MyWebClient code:
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
String hostname;
// YOUR HOSTNAME
hostname = "example.com";
Uri uri = Uri.parse(url);
if (url.startsWith("file:") || uri.getHost() != null && uri.getHost().endsWith(hostname)) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}
Related
I use volley to fetch content from a wordpress blog via its api.
The content I receive looks like this:
<p>Blog content blabla</p>\n
<div id=\ "pressrelease-link-345\" class=\ "sh-link pressrelease-link sh-hide\">
<a href=\ "#\" onclick=\ "showhide_toggle('pressrelease', 345, 'Show full article', 'Hide article'); return false;\" aria-expanded=\ "false\">
<span id=\"pressrelease-toggle-345\">Show full article</span>
</a>
</div>
<div id=\ "pressrelease-content-345\" class=\ "sh-content pressrelease-content sh-hide\" style=\ "display: none;\">
</p>\n
<p>more content which is displayed after expanding the text in the browser</p>
I'd like to show the full text in my app, so the whole -part should be removed. Is there a nicer way to do this than just building the string for each article (id, here 345)? I though maybe I could just 'filter' out the div using volley, but didn't figure out how yet.
If i have understand, you want remove a div from a HTML page with a WebView ?
private void yourwebv (){
String url = "mysite.com";
final WebView webview = (WebView) findViewById(R.id.WEBVIEW_ID);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebChromeClient(new WebChromeClient());
webview.setVisibility(View.INVISIBLE);
final ProgressBar ProgressBar = (ProgressBar) findViewById(R.id.ProgressBar);
ProgressBar.setVisibility(View.VISIBLE);
webview.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url){
String javaScript ="javascript:document.getElementsByClassName('YOURDIVCLASSNAME_REMOVE')[0]" +
".style.display='none';void(0);";
webview.loadUrl(javaScript);
Log.d("[WV]", " JS OK");
final ProgressBar ProgressBar = (ProgressBar) findViewById(R.id.ProgressBar);
ProgressBar.setVisibility(View.INVISIBLE);
webview.setVisibility(View.VISIBLE);
}
});
webview.loadUrl(url);
Log.d("[WV]", " WEBSITE + JS SCRIPT OK");
}
I'm trying to load html-code into an WebView.
webView = (WebView) getView().findViewById(R.id.mywebview);
webView.setVerticalScrollBarEnabled(true);
webView.setHorizontalScrollBarEnabled(true);
webView.setWebViewClient(getWebviewClient());
webView.addJavascriptInterface(getJavascriptInterface(), "HTMLOUT");
webView.getSettings().setJavaScriptEnabled(true);
webView.clearCache(true);
protected WebViewClient getWebviewClient() {
return new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && (url.startsWith("http://") || url.startsWith("mailto:"))) {
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
};
}
<h1>Title</h1>
<ul>
Lorem ipsum dolor sit amen www.test.com
</ul>
My problem now is that the link is not being detected (i guess due to the missing anchor tag).
Now when trying...
Spannable sp = new SpannableString(html);
Linkify.addLinks(sp, Linkify.ALL);
String html2 = Html.toHtml(sp);
and loading html2 into the webview, the links get displayed but the all the other tags are not rendered anymore but displayed as text.
Thanks for any help
I wanted to put variable from my activity and display it in html. Below is how I insert the variable into webview but I'm not sure how am I suppose to get the data from html and display it in "textview" form?
EDIT
Java
webView = (WebView)findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setDatabasePath("/data/data/com.example.hybrid/hybrid_user");
webView.loadUrl("file:///android_asset/www/index.html");
webView.loadUrl("javascript:callFromActivity(\""+userid+"\")");
html
<body>
<form>
<fieldset>
<legend>Hybrid Application</legend>
<p>
<label>UserName: </label>
</p>
<p id="mytext">Hello!</p>
<p>
<label>Mobile Number :</label>
<input type = "text"
id = "mobileNum" />
</p>
<button type="button"
onclick="updateRecord()">Submit</button>
<div id="output"></div>
</fieldset>
</form>
<script>
function errorHandler(transaction, error){
alert('Error:'+error.message+' (Code '+error.code+')');
return true;
}
window.onerror = errorHandler;
var shortName = 'hybrid_user';
var version = '1.0';
var displayName = 'Hybrid Database';
var maxSize = 65536;
var db = openDatabase(shortName, version, displayName, maxSize);
function updateRecord(id, textE1){
database.transaction(function(tx){
tx.executeSql("UPDATE hybrid_user SET mobile = ? WHERE userid = ?", [textE1.innerHTML, id], null, onError);
})
}
function callFromActivity(msg){
document.getElementById("mytext").innerHTML = msg;
}
</script>
I'm new to html and I don't know what's wrong with my code, it did not display out the userid in the html page. Any comments and answers will be appreciated!
Edit update
webView.loadUrl("javascript:callFromActivity(\""+userid+"\")");
Apparently is the system didn't go through this line of code. Is there anyway go through this code?
try change innerHTML for value like this:
function callFromActivity(msg) {
document.getElementById("mytext").value = msg;
}
webView.setWebViewClient(new WebViewClient(){
#Override
public void onPageFinished(WebView view, String url){
webView.loadUrl("javascript:callFromActivity(\""+userid+"\")");
}
});
I solved my problem with this. When the page loads finished it will execute the above code and get the userid from the activity.
Form Submit is not working in Android 4.0. The same code is working fine in the lower versions of Android.
Find my code for our reference
<form id="login-form" data-ajax="false" method="get" action="POST">
<div id="userPassLogin">
<div id="loginFormButtondiv" style="display: none;">
Back to Login
</div>
<div id="loginDiv">
<div data-role="fieldcontain" style="border: none; margin-top: 10px;">
<input style="width: 95%" type="email" class="placeholder" name="login" id="username" placeholder="Login ID" data-theme="c" value="Test286826.User286826#alere.com" />
</div>
<div data-role="fieldcontain" style="border: none; margin-top: 0px;">
<input style="width: 95%" type="password" class="placeholder" name="password" id="password" placeholder="Password" data-theme="c" value="P#ssw0rd" />
</div>
</form>
the controller code is,
'submit #login-form' : 'onSubmit',
the Method declaration and the definition is,
onSubmit : function(event)
{
alert('Inside the Form Submit');
if(isIOS){
nativeCommunication.callNativeMethod("networkcheck://isServerHosted?");
}
if(isAndroid || mHealth.util.webHostStatus){
alert('Inside the Form Submit');
event.preventDefault();
alert('Inside the Form Submit');
if(isAndroid){
alert('Inside the Form Submit');
this.doLogin();
}
}
},
Any help will be great.
Thanks
I fixed it by override WebViewClient
private class MyWebViewClient extends WebViewClient {
public String values = "";
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("?")) {
try {
values = URLDecoder.decode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
url = url.replace("?", "%45");
String args[] = url.split("%45");
view.loadUrl(args[0]);
}else{
view.loadUrl(url);
}
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
if(values.length()>0){
if(url.contains("page2.html")){
mWebView.loadUrl("javascript:getUrlVars(\""+values+"\");");
}
}
super.onPageFinished(view, url);
}
}
I have an HTML form inside a WebView. The form control looks like a regular button, but actually it is an html file with a transparent background. When I press the HTML submit button, I want the result to open in the browser, not in the webview. Currently it is opening in the current WebView which is wrecking my layout.
How do I do this?
Here is my Form
<string name="googlecheckout_html_button">
<![CDATA[
<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
<head>
<title>Google Checkout Button</title>
<script type=\"text/javascript\" language=\"javascript\">
function pass() {
return javaInterface.checkboxPass();
}
</script>
</head>
<body>
<form style=\"width: 121px;margin-left: auto;margin-right: auto;\" onsubmit=\"return pass();\" action=\"https://%1$sapi/checkout/v2/checkoutForm/Merchant/%2$s\" id=\"BB_BuyButtonForm\" method=\"post\" name=\"BB_BuyButtonForm\">
<input name=\"item_name_1\" type=\"hidden\" value=\"%3$s\" />
<input name=\"item_description_1\" type=\"hidden\" value=\"%3$s\" />
<input name=\"item_quantity_1\" type=\"hidden\" value=\"1\" />
<input name=\"item_price_1\" type=\"hidden\" value=\"%4$s\" />
<input name=\"item_currency_1\" type=\"hidden\" value=\"%5$s\" />
<input name=\"_charset_\" type=\"hidden\" value=\"utf-8\" />
<input type=\"hidden\" name=\"shopping-cart.items.item-1.merchant-private-item-data\" value=\"%6$s\" />
<input alt=\"Pay With Google Checkout\" src=\"https://%1$sbuttons/buy.gif?merchant_id=%2$s&w=121&h=44&style=trans&variant=text&loc=en_US\" type=\"image\" />
</form>
</body>
</html>
]]>
</string>
I am then using String.format(arg...) to populate the fields with appropriate values.
Here is by WebView
String form = String.format(getString(R.string.googlecheckout_html_button),
host,
merchantId,
item_name_1,
item_price_1,
item_currency_1,
private_item_data
);
if(Logging.DEBUG) Log.d(TAG, form);
browser = new WebView(ActivityActivate.this);
browser.setBackgroundColor(0);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
browser.getSettings().setSupportZoom(true);
browser.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view,
String url) {
return false;
}
});
//browser.getSettings().setLoadsImagesAutomatically(true);
browser.addJavascriptInterface(new JavascriptInterface(), "javaInterface");
//browser.loadData(header+formData+footer, "text/html", "UTF-8");
browser.loadDataWithBaseURL("https://checkout.google.com", form, "text/html", "UTF-8", null);
llPaymentButtons.addView(browser);
Forms are submitted to servers not to browsers. Make sure you have a correct URL where you are submitting the form.
To solve your problem you must override WebViewClient.shouldOverrideUrlLoading(..):
webview.setWebViewClient( new WebViewClient() {
public void shouldOverrideUrlLoading (WebView view, String url) {
return false;
}
});