Android中获取网页表单中的数据
[java]
package cn.testjavascript;
import java.util.StringTokenizer;
import android.os.Bundle;
import android.webkit.WebView;
import android.app.Activity;
/**
* Demo描述:
* 在Android中获取网页里表单中的数据
*/
public class MainActivity extends Activity {
private WebView mWebView;
private String date =null;
private String email = null;
private String username = null;
private String 易做图 = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init(){
mWebView=(WebView) findViewById(R.id.webView);
initWebViewSettings();
mWebView.loadUrl("file:///android_asset/form.html");
//注意addJavascriptInte易做图ce方法中第二参数
//它表示我们的java对象javaClass的别名.
//这样Javascript就可以通过该别名来调用Android中的方法
//即Javascript代码中的:window.testform.send(date+"|"+email+"|"+name+"|"+易做图);
//send是方法名
//testform是别名
mWebView.addJavascriptInte易做图ce(new Object() {
public void send(String userInfo) {
StringTokenizer userInfoStringTokenizer = new StringTokenizer(userInfo, "|");
date = userInfoStringTokenizer.nextToken();
email = userInfoStringTokenizer.nextToken();
username = userInfoStringTokenizer.nextToken();
易做图 = userInfoStringTokenizer.nextToken();
System.out.println("userInfoStringTokenizer="+userInfoStringTokenizer.toString());
System.out.println("date=" + date);
System.out.println("email=" + email);
System.out.println("username=" + username);
System.out.println("易做图=" + 易做图);
};
}, "testform");
}
private void initWebViewSettings(){
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.requestFocus();
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.getSettings().setBuiltInZoomControls(true);
}
}
package cn.testjavascript;
import java.util.StringTokenizer;
import android.os.Bundle;
import android.webkit.WebView;
import android.app.Activity;
/**
* Demo描述:
* 在Android中获取网页里表单中的数据
*/
public class MainActivity extends Activity {
private WebView mWebView;
private String date =null;
private String email = null;
private String username = null;
private String 易做图 = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init(){
mWebView=(WebView) findViewById(R.id.webView);
initWebViewSettings();
mWebView.loadUrl("file:///android_asset/form.html");
//注意addJavascriptInte易做图ce方法中第二参数
//它表示我们的java对象javaClass的别名.
//这样Javascript就可以通过该别名来调用Android中的方法
//即Javascript代码中的:window.testform.send(date+"|"+email+"|"+name+"|"+易做图);
//send是方法名
//testform是别名
mWebView.addJavascriptInte易做图ce(new Object() {
public void send(String userInfo) {
StringTokenizer userInfoStringTokenizer = new StringTokenizer(userInfo, "|");
date = userInfoStringTokenizer.nextToken();
email = userInfoStringTokenizer.nextToken();
username = userInfoStringTokenizer.nextToken();
易做图 = userInfoStringTokenizer.nextToken();
System.out.println("userInfoStringTokenizer="+userInfoStringTokenizer.toString());
System.out.println("date=" + date);
System.out.println("email=" + email);
System.out.println("username=" + username);
System.out.println("易做图=" + 易做图);
};
}, "testform");
}
private void initWebViewSettings(){
&n
补充:移动开发 , Android ,