foursquare授权url未在android webview中加载

时间:2013-10-26 06:55:29

标签: foursquare

我的登录webview未加载到android.But几个月前它很好。  我还写了一个从android访问foursquare的项目。  https://github.com/goutomroy/DroidSquare/blob/master/README.md
 当我尝试加载webview时,我发现了消息:  “与服务器的连接不成功”  我的错在哪里?

@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView() {

    String URL_LOGIN = "https://foursquare.com/oauth2/authenticate?"
            + "client_id="+ FoursquareConstants.CLIENT_ID 
            + "&response_type=code"
            + "&display=touch"
            + "&redirect_uri=" + FoursquareConstants.URL_CALLBACK;

    CookieSyncManager.createInstance(activity);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.acceptCookie();
    cookieManager.removeAllCookie();

    webView = new WebView(getContext());
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);
    settings.setBuiltInZoomControls(true);
    settings.setPluginState(PluginState.ON);
    webView.setVerticalScrollBarEnabled(true);
    webView.setHorizontalScrollBarEnabled(true);
    webView.setWebViewClient(new FoursquareWebViewClient());
    webView.loadUrl(URL_LOGIN);
    setContentView(webView);
}

 class FoursquareWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return false;
    }
    @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        Log.d("onReceivedError", errorCode +" : "+description+ " : " + failingUrl);
        super.onReceivedError(view, errorCode, description, failingUrl);

        dismissProgressDialog();
        LoginDialog.this.dismiss();
        responseHandler.onError(description);
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {

        Log.d("onPageStarted", url);
        super.onPageStarted(view, url, favicon);

        if(flag) 
            return;
        else if (url.startsWith(FoursquareConstants.URL_CALLBACK)) {
            flag = true;
            String urls[] = url.split("=");
            responseHandler.onSuccess(urls[1]);
            LoginDialog.this.dismiss();
            return;
        }

        else
            showOrUpdateProgressDialog("Loading...");

    }

    @Override
    public void onPageFinished(WebView view, String url) {
        Log.d("onPageFinished", url);
        super.onPageFinished(view, url);

        dismissProgressDialog();
    }

     @Override
     public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
         Log.d("onReceivedSslError", "error");
         handler.proceed(); // Ignore SSL certificate errors
     }
}

1 个答案:

答案 0 :(得分:3)

您应该检查清单文件中的互联网权限

<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>