I'm trying to make an Android app with a webview in which I have an html page. This one contains a "div" tag with the contentEditable property set to true.
My problem: by launching the app, I can't edit the text.
I've been doing a lot of searches on Google but there was nothing on this topic. I was wondering if there was any permission missing (as the one to reach the net in the manifest) but I'm able to edit input and textarea tags (among others). I've refered to the WebView's API, WebViewClient, WebChromeClient but I didn't find any method which would configure a particular permission in order to do that.
Does the webview understand the contentEditable property? It's not working, even if the webview is supposed to interpret html.
My activity:
public class WebAppStackOverFlowActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webView) ;
webView.setWebChromeClient (new WebChromeClient()) ;
webView.loadUrl("file:///android_asset/www/index.html") ;
}
}
My asset/www/index.html file:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input id="name" value="this is an input tag" />
<br />
<div contenteditable="true">this is an editable div tag</div>
<br />
<textarea rows="" cols="">this is a textarea tag</textarea>
</body>
</html>
My main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
contentEditable is supported by the default browser on Android version 3.0 (Honeycomb) and up (source).
So, if you're running this on Gingerbread, that would explain why it's not working.
Related
Scenario:
I'm using Android Robotium Solo (v5.6.3) to automate web page interactions within my app. I need to automate data entry into INPUT fields that are contained within an IFRAME but I do not have much luck!
The Problem:
When I attempt to use, for example, solo.waitForWebElement(By.id("room-number", 5000, true) and solo.typeTextInWebElement(By.id("room-number", "101"), solo is unable to locate the element.
The discussion on this related issue "Accessing an iFrame inside a WebView #794" (https://github.com/RobotiumTech/robotium/issues/794), suggests that it's possible to use "solo.getConfig().webFrame = XXX" to focus solo on the content of a specific IFRAME and then access the WebElements. Unfortunately, I've not been able to get it to work and haven't been able to find any full examples. I assume XXX might need to be the "id" of the IFRAME but in my scenario (where I don't have control of the source code for the web pages being automated) the IFRAME tag has no id assigned.
I've created a simple example test scenario:
index.html - the main page that hosts the IFRAME
<html>
<body bgcolor="#AA3333">
<div id="wrapper">
<iframe src="embed.html" width="100%" height="100%" frameborder="0"></iframe>
</div>
</body>
</html>
embed.html - the source for the IFRAME that contains the INPUT element.
<html>
<body bgcolor="#3333AA">
<div id="page-container" style="height:100vh; width:100%;">
<label>Room Number</label>
<input type="text" name="ROOM_NUMBER" id="room-number">
</div>
</body>
</html>
After reviewing the source code for Robotium in more detail I confirmed that using
solo.getConfig().webFrame = ['id' of IFRAME as a String]
allows subsequent calls to solo.typeTextInWebElement etc. to work OK as expected.
The trick in my scenario is that the parent page assigned no id to the IFRAME so I programatically assign one at runtime using the following javascript
document.getElementsByTagName("iframe")[0].id = "test";
and then use
solo.getConfig().webFrame = "test"
I am developing an android information app for farmers.Informations will be given in local indian language.I am using webview for that purpose.Informations are stored in html files.The problem is that the informtions which are in local language are not visible.How to solve this?
WebView mWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Getting reference to WebView of the activity_main layout
mWebView = (WebView) findViewById(R.id.webview);
// Loading an html page into webview
mWebView.loadUrl("file:///android_asset/text.html");
}
Activity main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res /android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/hello_world" />
</RelativeLayout>
html file
<html>
<head>
<meta http-equiv="content-type" content="text/html;" charset="UTF-8">
<style>
/** Specify a font named "MyFont",
and specify the URL where it can be found: */
#font-face {
font-family: "MyFont";
src: url('file:///android_asset/b.ttf');
}
h3 { font-family:"MyFont"}
</style>
</head>
<body>
<h3>
ಪ್ರಶಾಂತ
</h3>
</body>
You mean to say you want to show helloworld in regional language. For that you need to create res/values- folder. The android framework will automatically pick up the right language
Details:
http://developer.android.com/guide/topics/resources/localization.html
Below are couple of stackoverflow posts which might help you.
How to show local languages font.
How to use custom font with webview.
Try this
add this statement to your onCreate().
mWebView.getSettings().setJavaScriptEnabled(true);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Getting reference to WebView of the activity_main layout
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
// Loading an html page into webview
mWebView.loadUrl("file:///android_asset/text.html");
}
I want to work with html file, I did it when I deploy it, it won't workout (The input html page need to be shown but it shows webpage not available when I deploy ) ! Error msg also not in LOG !Any help please. Where is the wrong I'm doing ?
public class TestActivity extends Activity {
/** Called when the activity is first created. */
WebView webView =null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView =(WebView)findViewById(R.id.web);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///android-assets/www/index.html");
}
}
Here my javascript.
function sayhello(){
alert("hi", document.getElementById('name'),value);
}
and html file is here
<!DOCTYPE html>
<html>
<head>
<script src="index.js"></script>
</head>
<body>
What is ur name ?
<input id="name" value="">
<button onclick="sayhello()">say hello</button>
</body>
</head>
</html>
and the layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/web"
android:text="#string/hello"
/>
</LinearLayout>
You need to use:
file:///android-asset/www/index.html
Just get rid of the 's'
UPDATE:
You can also load pages with:
webView.loadDataWithBaseURL(null, html, "text/html", "utf-8",null);
Where the second param is your page to load.
I am working on a cross platform mobile application using phonegap (html,javascript) problem is selected item related image not display in iframe and this image display another page please see below code
<html>
<head>
<script>
function onchangeevent(mySelect)
{
PageIndex2=mySelect.selectedIndex;
{
if
(
mySelect.options[PageIndex2].value != "none"
)
{
frames['iframe2'].location.href = mySelect.options[PageIndex2].value;
}
}
}
</script>
</head>
<body>
<form name="form">
<p><select NAME="selectimage" SIZE="1" onChange="onchangeevent(this.form.selectimage)">
<option VALUE="none" SELECTED>Select a page and go</option>
<option VALUE="ic_launcher.png">one</option>
<option VALUE="icon.png">two</option>
</select> </p>
<p>
<iframe src="" name="iframe2" height="100%" width="100%">You need a Frames Capable browser to view this content.</iframe>
</p>
</form>
</body>
</html>
iframe tag not working android inbuild browser how can resolve the issue ? please tell any alternative tags supported all browsers.
Android browser supports iframe. I suspect it's one of the other attributes that may be causing an issue. I know scroll attribute can cause the iframe to not appear. Try a simpler version of the iframe with just the href and a width and height and see if it appears.
From the looks of it, the i-frame is working, it's most likely the select script, try using radio buttons see if that works.
For some reason several types of browsers are picky with the select form.
I wanted to use FusionCharts with android 2.2 (may be on emulator).
I tried using Javascript and the HTML but did not get the expected result.
Any help??
My code is as follows :
WebView web;
/** Called when the activity is first created. */
#Override
public void on Create(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
web=(WebView)findViewById(R.id.webView1);
web.loadUrl("file:///android_asset/Fusioncharts/myChart.html");
}
}
Also my html,xml files :
<html>
<head>
<title>My First chart using FusionCharts
</title>
<script type="text/javascript" src="JavaScripts/FusionCharts.js">
</script>
</head>
<body>
<div id="chartContainer">FusionCharts will load here!
</div>
<script type="text/javascript">
<!--
var myChart = new FusionCharts("Pie2D.swf? dataURL=Data.xml","myChartId", "400", "300", "0", "1" );
myChart.setXMLUrl("Data.xml");
myChart.render("chartContainer");
// -->
</script>
</body>
</html>
and Data.xml :
The above code just displays me : FusionCharts will load here!
Thanks
Sneha
EDIT> NEW CONTENT:
You might need to enable JavaScript and plugins for the WebView:
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
http://developer.android.com/reference/android/webkit/WebView.html
What does "install Flash plugin" in WebView mean?
How to Enable Flash Plugin in Webview?
Also you might need to set proper path to the SWF and JS files. Please debug or attach code here.
OLD CONTENT:
There seems to be a JavaScript error or FusionCharts not getting loaded to do the rendering as stated by Duniyadnd.
Please check the Android debug (using adb logcat or other processes) if it traces any error.
Moreover, I did an implementation using PhoneGap which you can check-out from:
PhoneGap API to query call-logs
This is a small PhoneGap Android application which has FusionCharts to show call logs from the device. The post though showcases creation of plugin to get the calllog, you might derive the other elements which you require. Hope this might help.