- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
当我点击 webview 页面中的按钮时出现错误。据说,当我单击按钮时,它将更改为 google 站点。以下是代码和错误:-
主 Activity .java
package com.mt.nad.testwebapp;
import android.content.Context;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
private WebView webC;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webC = (WebView)findViewById(R.id.webView1);
webC.addJavascriptInterface(new JavaScriptInterface(), "CallJavaAdapter");
webC.setWebViewClient(new WebViewClient());
WebSettings webS = webC.getSettings();
webS.setJavaScriptEnabled(true);
webC.loadUrl("http://10.0.2.2/test-java-adapter/");
}
private class JavaScriptInterface{
JavaScriptInterface() {
}
@JavascriptInterface
public void gotoSite() {
//Toast.makeText(mContext, url, Toast.LENGTH_SHORT).show();
webC.clearCache(true);
webC.loadUrl("http://google.com");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml
<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" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView" />
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mt.nad.testwebapp" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test Only</title>
<link rel="stylesheet" href="">
</head>
<body>
<div>
<input type="button" value="Go To Site" onClick="window.CallJavaAdapter.gotoSite()">
</div>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
</body>
</html>
日志猫
12-29 03:54:04.099 2793-2838/com.mt.nad.testwebapp W/WebView﹕ java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {2e799371} called on Looper (JavaBridge, tid 210) {72d6c48}, FYI main Looper is Looper (main, tid 1) {2e799371})
at android.webkit.WebView.checkThread(WebView.java:2194)
at android.webkit.WebView.clearCache(WebView.java:1451)
at com.mt.nad.testwebapp.MainActivity$JavaScriptInterface.gotoSite(MainActivity.java:56)
at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:28)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
12-29 03:54:04.100 2793-2838/com.mt.nad.testwebapp W/System.err﹕ java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {2e799371} called on Looper (JavaBridge, tid 210) {72d6c48}, FYI main Looper is Looper (main, tid 1) {2e799371})
12-29 03:54:04.100 2793-2838/com.mt.nad.testwebapp W/System.err﹕ at android.webkit.WebView.checkThread(WebView.java:2204)
12-29 03:54:04.100 2793-2838/com.mt.nad.testwebapp W/System.err﹕ at android.webkit.WebView.clearCache(WebView.java:1451)
12-29 03:54:04.101 2793-2838/com.mt.nad.testwebapp W/System.err﹕ at com.mt.nad.testwebapp.MainActivity$JavaScriptInterface.gotoSit (MainActivity.java:56)
12-29 03:54:04.101 2793-2838/com.mt.nad.testwebapp W/System.err﹕ at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
12-29 03:54:04.101 2793-2838/com.mt.nad.testwebapp W/System.err﹕ at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:28)
12-29 03:54:04.101 2793-2838/com.mt.nad.testwebapp W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
12-29 03:54:04.101 2793-2838/com.mt.nad.testwebapp W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
12-29 03:54:04.101 2793-2838/com.mt.nad.testwebapp W/System.err﹕ at android.os.HandlerThread.run(HandlerThread.java:61)
12-29 03:54:04.101 2793-2838/com.mt.nad.testwebapp W/System.err﹕ Caused by: java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {2e799371} called on Looper (JavaBridge, tid 210) {72d6c48}, FYI main Looper is Looper (main, tid 1) {2e799371})
12-29 03:54:04.102 2793-2838/com.mt.nad.testwebapp W/System.err﹕ at android.webkit.WebView.checkThread(WebView.java:2194)
12-29 03:54:04.102 2793-2838/com.mt.nad.testwebapp W/System.err﹕ ... 7 more
12-29 03:54:04.127 2793-2793/com.mt.nad.testwebapp I/chromium﹕ [INFO:CONSOLE(19)] "Uncaught Error: Java exception was raised during method invocation", source: http://10.0.2.2/test-java-adapter/ (19)
12-29 03:54:04.159 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
12-29 03:54:04.175 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
12-29 03:54:04.274 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ **** ERROR unknown type 0x0 (glSizeof,72)
12-29 03:54:04.299 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
12-29 03:54:04.323 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
12-29 03:54:04.448 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ **** ERROR unknown type 0x0 (glSizeof,72)
12-29 03:54:04.468 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
12-29 03:54:04.499 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
12-29 03:54:04.527 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ **** ERROR unknown type 0x0 (glSizeof,72)
12-29 03:54:04.537 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
12-29 03:54:04.549 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
12-29 03:54:04.580 2793-2832/com.mt.nad.testwebapp E/eglCodecCommon﹕ **** ERROR unknown type 0x0 (glSizeof,72)
来源:
http://10.0.2.2/test-java-adapter/ (19)
是指
<input type="button" value="Go To Site" onClick="window.CallJavaAdapter.gotoSite()">
如果使用 Toast 或 TextView,在单击按钮时可以更改,但对于 WebView loadurl(),它不会加载...
我指的是:Android App: How to loadUrl in WebView from another class?但仍然没有运气......
最佳答案
改变
@JavascriptInterface
public void gotoSite() {
//Toast.makeText(mContext, url, Toast.LENGTH_SHORT).show();
webC.clearCache(true);//Here you call the methond in other thread
webC.loadUrl("http://google.com");
}
到:
@JavascriptInterface
public void gotoSite() {
//Toast.makeText(mContext, url, Toast.LENGTH_SHORT).show();
new Handler().post(new Runnable() {
@Override
public void run() {
webC.clearCache(true);//Here you call the methond in UI thread
webC.loadUrl("http://google.com");
}
});
}
关于java - WebView loadurl() - 安卓应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27683567/
我的 WebView 适用于 Google.com 等网站,但不会加载特定页面。 简单地显示subscribe to feedburner(我制作这个网站是为了反射(reflect)一个转换后的新闻提
我的 webview 收费从服务器查看页面 private String url = "http://192.168.33.37/gestpresenze/index.html"; @Override
我已经使用 addJavascriptInterface() 方法向 WebView 添加了一个 Javascript 接口(interface)对象,我正在尝试使用 WebView.loadUrl(
我有一个测试页面,可以为测试的每个问题从 HTML 加载数据。每当我从 HTML 中获取视频作为 iFrame 时,我都会将其解析为数据 URI,然后在 WebView 中显示该视频。我使用同一页面来
我写了一个方法来从用户那里获取地址信息,然后将其显示在谷歌的 map 上。这是我写的方法 function doRemoteMapEmployee(e) { var mapEmployeeAddres
刚刚开始使用 Electron,我希望能够使用 loadURL 加载页面,但不替换整个页面。 这里的想法是如何使用像部分/模板这样的东西,这样我就可以在顶部和底部拥有一致的布局,但将不断变化的内容引入
(首先,我要声明一下,我的专业领域是 HTML5(和 php/coldfusion),而我是 Java/Android 的初学者) 在我的 onCreateOptionsMenu 中,我有以下代码来处
我有一个从 android webview 播放音乐的应用程序,我已经自动播放到下一首歌曲,为了播放下一首歌曲,我需要在 webview 中加载新的 url。一切正常。但是当我从 webview 添加
我的 Android 应用程序有一个更新类,在同一个应用程序中,我有另一个通过 webview 打开网站的类。问题是我想让更新类加载 url 但不显示它,然后缓存它(如果可能的话,所以如果用户离线它应
我想创建一个可以在应用程序中打开网站的应用程序。所以我想使用webview。但是,当我使用“loadurl”功能时,该应用程序在手机(Android 4.2.2)上崩溃了。你知道问题出在哪里吗? 错误
我试图在 webview 中打开 url,但它在外部浏览器中打开 url。 我的代码是 public class MainActivity extends Activity { private
我知道要在 webview 中运行 javascript 函数,我们需要在 loadUrl() 中加载它。在我的程序中,当我在 loadUrl 中使用它时,一切正常 javascript 被调用,但
我有三个 fragment 。我已经从第三个 fragment 向第一个 fragment 发送了一个字符串(URL)。第一个 fragment 有一个 webView 。我想在我从第三个 fragm
我的 WebView 是这样设置的 public class Webview extends Activity { private WebView webView; @Override protect
我正在尝试加载页面,然后执行 JavaScript 代码,如下所示: webview.setWebViewClient(new WebViewClient() { @Over
当我点击 webview 页面中的按钮时出现错误。据说,当我单击按钮时,它将更改为 google 站点。以下是代码和错误:- 主 Activity .java package com.mt.nad.t
是否可以将值传递给 webView.loadUrl 中提到的 URL?像这样的?? webView.loadUrl("file:///android_asset/www/index.html#valu
当尝试在我的 Android Things webview 中加载 url 时,页面最初加载,然后使 UI 崩溃并显示一条指向 IoT FrameworkPackageStubs 的错误消息。 我在
这是我的代码: package sai.datla.game; import android.app.Activity; import android.os.Bundle; import androi
backbone.js 网站上没有 Backbone.history.loadURL 的文档 http://backbonejs.org/#History-start虽然我对它在我看过的某些应用程序中
我是一名优秀的程序员,十分优秀!