ログイン WebView が Android に読み込まれません。しかし、数か月前は問題ありませんでした。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
}
}