2

I've just received the PhoneGap solution from by sub-contractor in order to test it on my phone before launch.

I import the project into Eclipse and it all looks fine.

I can test the app locally on my computer by opening the index.html file:

file://E:/AppDevelopment/Workspace/myproject/assets/www/index.html

So far so good. Then I try launching this an my phone ( via USB cabel). The front page opens, but the CSS is missing. And when I click any link, I get the following message:

"A network error occurred. (file:///android_asset/www/car.html?carID=106"

Has anyone had similar problems? Any suggestions to how I can debug what is wrong?

UPDATE

Following Dmyto's suggestion, I'm trying to change the onReceivedError. But I only get coding errirs.

package com.phonegap.mysite;

import android.os.Bundle;
import org.apache.cordova.*;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Mysiteextends DroidGap {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///android_asset/www/index.html");

    }

/** This is where it goes wrong **/

    WebView webview = new WebView(this);

    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Log.i("WEB_VIEW_TEST", "error code:" + errorCode);
                super.onReceivedError(view, errorCode, description, failingUrl);
        }

}
Steven
  • 19,224
  • 47
  • 152
  • 257

3 Answers3

2

Without seeing your index.html code it is hard to tell if you are referencing your css files properly. Also, that url: file:///android_asset/www/car.html=carID=106 doesn't seem valid? What is with the =carID=106? A proper URL should be ?carID=106. But wait there's more, there is a bug on Android where url paramters are not read properly.

It's a bug on Android. You should go star it:

https://code.google.com/p/android/issues/detail?id=17535

In the meantime use localStorage.setItem()/getItem() to pass values between pages.

stealthjong
  • 10,858
  • 13
  • 45
  • 84
Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • Sorry, the URL was a typo. I'm using `?` and not `=`. The correct url is `file:///android_asset/www/car.html?carID=106`. As stated in my Q, the app works fine when I test it on my computer (and Eclipse), just not on my phone. I have no experience coding app for Android, so I'm pretty blank on **where** the various codes goes. – Steven May 03 '12 at 15:27
  • 1
    Right so you are being tripped up by the bug in the Android OS. So if you want to pass info from one page to another you'll need to use localStorage. – Simon MacDonald May 04 '12 at 01:33
  • After some testing you are absolutely right. My question is; Will using localStorage work for iOS and Windows phones? – Steven May 04 '12 at 08:37
  • I'm sure it will work for iOS and I'm pretty sure it'll work for WP but I haven't tested with one of those. – Simon MacDonald May 04 '12 at 14:31
0

You can set WebViewClient to your web view, and ovveride onReceivedError method.

Dmytro Danylyk
  • 19,684
  • 11
  • 62
  • 68
  • I've never coded one line for a app (henche sub-contractor). In what file do I set the WebViewClient? – Steven May 03 '12 at 15:12
  • Please reffer to documentation: http://developer.android.com/reference/android/webkit/WebView.html – Dmytro Danylyk May 03 '12 at 15:15
  • Yes I see it, but it doesn't say where. Should I put it on every *.html file that I want to test? Or should this be put in some js script? **Edit:** I think I found the answer here: http://developer.android.com/resources/tutorials/views/hello-webview.html – Steven May 03 '12 at 15:19
0

You might need to use IceCreamCordovaWebViewClient

@Override
    public void init() {
    super.init(webView, new IceCreamCordovaWebViewClient(this, webView), new CordovaChromeClient(this, webView));
}
Clayton Rabenda
  • 5,229
  • 2
  • 19
  • 16