java - 网站不会在 android webview 中加载,但在 android 浏览器中工作正常

标签 java javascript android android-intent webview

这让我烦恼了一段时间,我真的需要一些帮助。我在 portfoliobox.net 上创建了一个网站,它在 chrome 和我在 android 上尝试过的所有其他浏览器(实际手机,而不是模拟器)上都运行良好,但是我想将它变成一个大学项目的应用程序。我的 webview 应用程序可以很好地加载其他网站,但由于某种原因不能加载我的网站,所以是的,我已经正确设置了权限并且启用了 javascript。这可能很简单,但我是一个大菜鸟,没有太多线索。

这是日志

04-30 22:08:56.954: W/BindingManager(8365): Cannot call determinedVisibility() - never saw a connection for the pid: 8365
04-30 22:08:56.962: E/com.parse.push(8365): successfully subscribed to the broadcast channel.
04-30 22:08:56.973: D/GCM(2579): COMPAT: Multi user ser=0 current=0
04-30 22:08:56.989: D/GCM(11959): GcmService start Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService (has extras) } com.google.android.c2dm.intent.REGISTER
04-30 22:08:57.145: I/Icing(2579): Indexing DBC59092704C7216FC04EAC8683F4EE7F5C1F3E0 from com.google.android.googlequicksearchbox
04-30 22:08:57.302: W/SQLiteConnectionPool(2579): A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-30 22:08:57.302: W/SQLiteConnectionPool(2579): A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/help_responses.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-30 22:08:57.306: W/SQLiteConnectionPool(2579): A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/metrics.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-30 22:08:57.333: I/Icing(2579): Indexing done DBC59092704C7216FC04EAC8683F4EE7F5C1F3E0
04-30 22:08:57.333: D/PowerManagerService(912): releaseWakeLockInternal: lock=289528107 [Icing], flags=0x0
04-30 22:08:57.377: D/PowerManagerService(912): acquireWakeLockInternal: lock=1014891468, flags=0x1, tag="NetworkStats", ws=null, uid=1000, pid=912
04-30 22:08:57.406: D/PowerManagerService(912): releaseWakeLockInternal: lock=1014891468 [NetworkStats], flags=0x0
04-30 22:08:58.035: I/chromium(8365): [INFO:CONSOLE(0)] "'webkitIDBRequest' is deprecated. Please use 'IDBRequest' instead.", source:  (0)
04-30 22:08:58.270: I/chromium(8365): [INFO:CONSOLE(1)] "HARD RESET!!", source: http://www.broadbentstudios.com/application/_output/pb.out.front.js?v=7 (1)
04-30 22:08:58.277: I/chromium(8365): [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot read property 'clear' of null", source: http://www.broadbentstudios.com/application/_output/pb.out.front.js?v=7 (1)

主.xml

<?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="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/mainWebView"
      android:scrollbarSize="10dp"
      android:scrollbarThumbVertical="@drawable/customscroll">
     </WebView>


</LinearLayout>

BroadbentStudios.java

package com.broadbentstudios;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.parse.ParseAnalytics;

public class BroadbentStudios extends Activity {

    WebView webView;
    /** Called when the activity is first created. */
    @SuppressLint("SetJavaScriptEnabled")
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        webView = (WebView) findViewById(R.id.mainWebView);
        webView.setBackgroundColor(0x00000000);
        webView.setHorizontalScrollBarEnabled(false);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.loadUrl("http://www.broadbentstudios.com/");

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }



        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView!=null && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    {

        ParseAnalytics.trackAppOpenedInBackground(getIntent());
    }

}

我也使用 Parse 来推送新内容的通知,但我也尝试了一个没有它的干净的 webview 应用程序,但它没有用,所以我很确定不是那样。

我会认为,因为它在浏览器中运行良好,所以我的应用程序在某个地方搞砸了,但我想我可能是错的。任何帮助将不胜感激,即使它是我的网站而不是我的应用程序,也很高兴知道。谢谢。

最佳答案

好吧,我已经搜索了大约 2 个月的时间来寻找这个问题的答案,当我来到这里寻求帮助时,我自己找到了答案哈哈,这很典型。无论如何,对于处于类似情况的任何人,除了启用 javascript 之外,您还需要通过添加来启用 D​​om 存储;

webView.getSettings().setDomStorageEnabled(true);

将 webView 更改为您的名称,您应该可以开始了。

希望这对某人有帮助。

关于java - 网站不会在 android webview 中加载,但在 android 浏览器中工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29978082/

相关文章:

java - 如何以 Java 格式打印嵌套 Hashmap

java - Java 1.6.0 中的 UnsupportedClassVersionError 异常

javascript - 如何模拟进行 AJAX 调用的方法?

java - Android/Java - 将转义控制字符转换为转义 Unicode 字符

android.database.sqlite.SQLiteException : near "?": syntax error (code 1):

android - 在Android中使用路径前缀

java - 学习 Java 字节码和 JVM

java - 如何在 Java 中更改文本框的背景颜色一秒钟?

javascript - Facebook 登录警告

javascript - Bootstrap 3 - 所有页面的固定高度