我在测试 android 2.2 时遇到了一个有趣的问题。我的测试是使用 webview api,
webview.loadUrl(url);
如果 url 来自任何公共域,例如 www.google.com,则网络内容呈现得非常好。(url="http://www.google.com") 如果 url 来自本地主机,例如端口为 8080 的 tomcat,则也会呈现 Web 内容。(url="http://10.123.21.111:8080/MyWeb") 但如果 url 来自其他端口,例如具有端口 9080 的 websphere,则不会呈现 Web 内容。(url="http://10.123.21.111:9080/MyWeb") 没有抛出异常,在模拟器上显示空白。
不同的端口需要设置吗?任何人都可以回答这个问题吗?
谢谢。
约翰
有一种方法可以从webview调用javascript函数,然后让它调用Java中的方法来返回结果.就像在如何从android的webview中获取javascript的返回值一样?
现在,javascript函数可能会失败(比如由于javascript文件中的拼写错误).在这种情况下,我想在Java中执行一些故障转移代码.有什么好办法呢?
我当前的代码如下所示:
在Java中:
private boolean eventHandled = false;
@Override
public void onEvent() {
eventHandled = false;
webview.loadUrl("javascript:handleEvent()");
// Wait for JS to handle the event.
try {
Thread.sleep(500); // milliseconds
} catch (InterruptedException e) {
// log
}
if (!eventHandled) {
// run failover code here.
}
}
public final MyActivity activity = this;
public class EventManager {
// This annotation is required in Jelly Bean and later:
@JavascriptInterface
public void setEventHandled() {
eventHandled = true; …Run Code Online (Sandbox Code Playgroud) 当我按下菜单按钮时,我想刷新我的网页视图.这是我的代码:
TuzzaMobileActivity.java
package com.wiseheart.TuzzaMobile;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class TuzzaMobileActivity extends Activity {
final Activity activity = this;
private WebView webView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, …Run Code Online (Sandbox Code Playgroud) 我正在使用Android的WebView组件来显示带有POI的Google地图.为了显示POI,我使用的是JavaScript API类google.maps.Marker.
问题是,当地图上显示所有350个POI时,它们使WebView变得缓慢且几乎无法使用......
如何优化???
是否有任何API,例如将地图缩放级别与显示的标记数量放在一起?例如,如果缩放级别为0,例如显示10个POI,并且当缩放级别为10时,将显示所有适合视图端口的POI ...
感谢您的帮助,问候,彼得
android google-maps google-maps-api-3 android-maps android-webview
我有一个使用WebView显示网页的活动.在该页面中,有一个指向YouTube视频的链接(因此它不是我可以或需要嵌入的视频).
问题是视频无法播放 - 我可以通过点击图标看到视频预览图像,但点击它没有响应.有什么可以做的吗?
public class DisplayWebPage extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.display_web_page);
Bundle extras = getIntent().getExtras();
String url = extras.getString("url");
WebView webview = (WebView)findViewById(R.id.WebView1);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(url);
}
}
Run Code Online (Sandbox Code Playgroud) 我需要构建一个Android应用程序,让您可以在我的应用程序中查看网页.我需要这不是在浏览器中,而是我的应用程序.我找到了答案以及加载页面时的一些选项.在我测试过后,我想我会尝试分享我在这里找到的信息.....
我有一个WebView应该显示www.google.com 的基本应用程序.虽然可以通过内置浏览器访问该网站,但我无法通过内置浏览器访问WebView.我在各种论坛上经历了大量的问题并纳入了所有建议,但似乎没有任何效果.我已经确保:
1.uses-permission允许互联网访问的manifest标签是标签的子项.
2.为WebView启用了javascript.
清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sriram.hellowebview"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".helloWebview"
android:label="@string/title_activity_hello_webview" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
布局:
<?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:id="@+id/helloWebview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
码:
/* Program to create sample webview.
* Steps:
* 1. Create webview.
* 2. Show some website in …Run Code Online (Sandbox Code Playgroud) 嗨,我已经在 stackoverflow 中尝试了所有可用的解决方案,但没有任何效果,单击按钮时应用程序停止。请帮帮我。
每当我单击按钮时,应用程序就会崩溃。我希望应用程序在单击按钮时在 webview 中打开 url。请帮助我,非常感谢任何帮助。
任何人都可以发布修改后的代码。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentTop="true"
android:text="@string/button01"
android:onClick="onClick"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentTop="true"
android:text="@string/button02"
android:onClick="onClick"/>
</LinearLayout>
------------------------------
screen3.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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" >
<WebView
android:id="@+id/webview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
-----------------------------------------------------
mainactivity.java
package com.example.webview;
import android.support.v7.app.ActionBarActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个与常规WebView完全相同的自定义WebView,除了它有圆角.圆角需要透明,因为我想将此WebView放在对话框中.
我尝试制作我的自定义类:
public class RoundedWebView extends WebView
{
private Context context;
private int width;
private int height;
public RoundedWebView(Context context)
{
super(context);
initialize(context);
}
public RoundedWebView(Context context, AttributeSet attrs)
{
super(context, attrs);
initialize(context);
}
public RoundedWebView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
initialize(context);
}
private void initialize(Context context)
{
this.context = context;
}
// This method gets called when the view first loads, and also whenever the
// view changes. Use this opportunity to save the view's …Run Code Online (Sandbox Code Playgroud) android google-chrome android-webview google-plus google-chrome-webview
android ×10
android-webview ×10
java ×3
android-maps ×1
button ×1
google-maps ×1
google-plus ×1
webview ×1