webview

Android WebView JavaScript交互

旧时模样 提交于 2020-01-11 20:59:20
今天介绍一下,Android中Webview与JavaScript的交互,首先是在布局文件里添加webview控件: [html] view plain copy < WebView android:id= "@+id/webview" android:layout_width= "fill_parent" android:layout_height= "fill_parent" /> 然后是在manifest里添加权限: [html] view plain copy < uses-permission android:name="and 要是webview能够与JavaScript交互,首先需要webview要启用JavaScript: [html] view plain copy WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); 然后创建JavaScript的接口: [java] view plain copy public class WebAppInterface { Context mContext; /** Instantiate the interface and set the context */ WebAppInterface

Android 中 java 与 webview 的交互

牧云@^-^@ 提交于 2020-01-11 20:52:55
Android 中 java 与 webview 的交互 - - ITeye技术网站 Android 中 java 与 webview 的交互 Java Android webkit JavaScript UI android 的webkit的api的开放程度还是非常不错,java可以和webview内的javascript很好的交互。下面的小例子可以说明这一点。 先看我们的html文档: Html代码 < html > < script language = "javascript" > /* This function is invoked by the activity */ function wave() { alert("1"); document.getElementById("droid") .src = "android_waving.png" ; alert("2"); } </ script > < body > <!-- Calls into the javascript interface for the activity --> < a onClick = "window.demo.clickOnAndroid()" > < div style ="width:80px; margin:0px auto; padding:10px; text-align

Android中webView与javascript交互

。_饼干妹妹 提交于 2020-01-11 17:39:18
主要是通过addJavaScipteInterface(Object obj,String Interfacename) 方法将一个java对象绑定到一个javaScipte对象中,javaScripte对象名就是interfaceName package com.king.android.net; import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; import com.king.android.R; /** * 描述:webview与js互用 * 作者:Andy.Liu * 时间: 2012-7-26 上午08:24:06 * */ public class WebAndJsActivity extends Activity { private WebView mWebView = null ; private PersonalData mPersonalData; // 保存数据 @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.webview_layout);

WebView Js注入

↘锁芯ラ 提交于 2020-01-11 17:28:11
注入前: 注入后: 主界面: [java] view plain copy package com.example.webviewjsdemo; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast; public class MainActivity extends Activity { private WebView wv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); wv = (WebView) findViewById(R.id.wv_main); wv.setWebChromeClient( new

WebView into a Fragment (android.support.v4)

做~自己de王妃 提交于 2020-01-11 17:09:43
问题 I got a tab menu using a ViewPager . Each tab contains fragments from android.support.v4 package (compatibility with old SDKs). One of the fragment is a WebView (called FragmentWeb ) and I want it to stay into the pager layout. The problem is when my WebView is inflated, it runs in fullscreen mode. Is there a way to keep web browser under my tabs ? Thank you My Fragment Class : FragmentWeb.java public class FragmentWeb extends Fragment { public View onCreateView(LayoutInflater inflater,

How to take a screenshot when a webview finished rending

最后都变了- 提交于 2020-01-11 13:29:07
问题 I want to take a screenshot when a webview finished rending.The follow is my code: -(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { if (frame != [sender mainFrame]) { return; } NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:[sender bounds]] autorelease]; if (rep){ NSImage *img = [[NSImage alloc] initWithData:[rep TIFFRepresentation]]; NSData* imgData = [img TIFFRepresentation]; NSArray* deskTopArrayPaths =

Twitter video not loading android webview

家住魔仙堡 提交于 2020-01-11 13:00:50
问题 When playing twitter video in android web view it shows the message 'by playing this video you agree to the Twitter use of cookies' and video is not played after that. if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true); } else CookieManager.getInstance().setAcceptCookie(true); } webView.getSettings().setJavaScriptEnabled(true); webView.setBackgroundColor(Color.parseColor("#ffffff")); webView.loadDataWithBaseURL(

Twitter video not loading android webview

不羁的心 提交于 2020-01-11 13:00:40
问题 When playing twitter video in android web view it shows the message 'by playing this video you agree to the Twitter use of cookies' and video is not played after that. if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true); } else CookieManager.getInstance().setAcceptCookie(true); } webView.getSettings().setJavaScriptEnabled(true); webView.setBackgroundColor(Color.parseColor("#ffffff")); webView.loadDataWithBaseURL(

Android: Character encoding raw resource files

蹲街弑〆低调 提交于 2020-01-11 10:33:34
问题 I'm in the process of translating one of my apps to Spanish, and I'm having a character encoding problem with a raw HTML file I'm sticking into a WebView. I have the spanish translation of the file in my raw-es folder, and I'm reading it in with the following function: private CharSequence getHtmlText(Activity activity) { BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.help), "utf-8")); String line; StringBuilder buffer = new

Suppress “Failed to load resource: net::ERR_FILE_NOT_FOUND” in Chrome Packaged App

故事扮演 提交于 2020-01-11 09:24:26
问题 I get the message "Failed to load resource: net::ERR_FILE_NOT_FOUND" in the console when a webview in a Chrome Packaged App tries to load a non-existent local file. This is expected, because the program is supposed to check a couple of different location, starting with the local system and then switching to a remote server as a second try. The problem is that there are a lot of these messages in the console, which makes it very difficult to use the console for anything else. Is there a way to