0

在我添加端口之前,我的 WebView 运行良好。此时我看不到任何类型的错误,并且在我的 HTTP 流量中什么也看不到。

private Context vContext;
private String vPackageName;
private String vPlacementID;

static private double TRACK_VERSION = 1.0;
static private String TRACK_HOST = "foobar.com:8007";
static private String TRACK_HANDLER = "/event";

public void reportAppOpen(Context context, String placementID) {
    Log.d("FOO", "Tracking");
    if (context == null) {
        return;
    }
    vContext = context;
    vPackageName = vContext.getPackageName();
    vPlacementID = placementID;

    WebView webview = new WebView(context);
    webview.setVisibility(WebView.GONE);
    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Log.d("FOO", "error code:" + errorCode);
                super.onReceivedError(view, errorCode, description, failingUrl);
        }
     });
    webview.getSettings().setJavaScriptEnabled(true);

    List<NameValuePair> params = trackingParams();
    String paramString = URLEncodedUtils.format(params, "utf-8");
    String url = "http://" + TRACK_HOST + TRACK_HANDLER;
    webview.postUrl(url, EncodingUtils.getBytes(paramString, "base64"));

    Log.d("FOO", "Loading URL");        
}

我知道我的代码中还有其他一些奇怪的东西,但现在我只想专注于postUrl开始工作。

编辑:在 logcat 我发现这不确定它是否相关。

10-19 13:44:21.560: D/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
4

1 回答 1

1

请尝试使用 WebChromeClient 并覆盖以下方法:

   @Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
    // TODO Auto-generated method stub
    Log.v("ChromeClient", "invoked: onConsoleMessage() - " + sourceID + ":"
            + lineNumber + " - " + message);
    super.onConsoleMessage(message, lineNumber, sourceID);
}

@Override
public boolean onConsoleMessage(ConsoleMessage cm) {
    Log.v("ChromeClient", cm.message() + " -- From line "
            + cm.lineNumber() + " of "
            + cm.sourceId() );
    return true;
}

调试问题..

于 2012-10-19T21:37:48.297 回答