最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Website won't load in android webview but works fine in android browsers - Stack Overflow

programmeradmin6浏览0评论

This has been annoying me for a while now and I could really use some help. I have a website created on portfoliobox which works fine in chrome and every other browser I tried on android (actual phones, not emulators), however I wanted to make it into an app for part of a University project. My webview app loads other websites fine but not mine for some reason, so yes I have set the permissions right and I have javascript enabled. It could be something simple but I'm a major noob and haven't got much of a clue.

Here is the logcat

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/.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=.google.android.c2dm.intent.REGISTER pkg=.google.android.gms cmp=.google.android.gms/.gcm.GcmService (has extras) } .google.android.c2dm.intent.REGISTER
04-30 22:08:57.145: I/Icing(2579): Indexing DBC59092704C7216FC04EAC8683F4EE7F5C1F3E0 from .google.android.googlequicksearchbox
04-30 22:08:57.302: W/SQLiteConnectionPool(2579): A SQLiteConnection object for database '/data/data/.google.android.gms/databases/auto_plete_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/.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/.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: .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: .out.front.js?v=7 (1)

Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns: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 .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 .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("/");

        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());
    }

}

I also use Parse for push notifications for new content but I tried a clean webview app without it too and that didn't work so I'm pretty sure it's not that.

I would think that because it works fine in browsers it is my app messing up somewhere, but I could be wrong I guess. any help would be greatly appreciated, even if it's my website and not my app, it would be good to know. Thank you.

This has been annoying me for a while now and I could really use some help. I have a website created on portfoliobox which works fine in chrome and every other browser I tried on android (actual phones, not emulators), however I wanted to make it into an app for part of a University project. My webview app loads other websites fine but not mine for some reason, so yes I have set the permissions right and I have javascript enabled. It could be something simple but I'm a major noob and haven't got much of a clue.

Here is the logcat

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/.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=.google.android.c2dm.intent.REGISTER pkg=.google.android.gms cmp=.google.android.gms/.gcm.GcmService (has extras) } .google.android.c2dm.intent.REGISTER
04-30 22:08:57.145: I/Icing(2579): Indexing DBC59092704C7216FC04EAC8683F4EE7F5C1F3E0 from .google.android.googlequicksearchbox
04-30 22:08:57.302: W/SQLiteConnectionPool(2579): A SQLiteConnection object for database '/data/data/.google.android.gms/databases/auto_plete_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/.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/.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./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./application/_output/pb.out.front.js?v=7 (1)

Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android./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 .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 .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./");

        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());
    }

}

I also use Parse for push notifications for new content but I tried a clean webview app without it too and that didn't work so I'm pretty sure it's not that.

I would think that because it works fine in browsers it is my app messing up somewhere, but I could be wrong I guess. any help would be greatly appreciated, even if it's my website and not my app, it would be good to know. Thank you.

Share Improve this question edited Apr 30, 2015 at 21:47 Lewis Broadbent asked Apr 30, 2015 at 21:28 Lewis BroadbentLewis Broadbent 7991 gold badge7 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

Well I've been searching for about 2 months for an answer to this and as soon as I e here for help I find it myself haha, typical. Anyway, for anybody in a similar situation, as well as enabling javascript you also need to enable Dom storage by adding in;

webView.getSettings().setDomStorageEnabled(true);

Change webView to whatever yours is called and you should be good to go.

Hope this helps someone.

发布评论

评论列表(0)

  1. 暂无评论