【问题标题】:Some webpages not loading in android's webview某些网页未在 android 的 webview 中加载
【发布时间】:2014-08-28 17:36:11
【问题描述】:

我一直在试用 instagram API。我不明白为什么授权页面没有加载到我的 webview 中。 yahoo 和 google 等其他页面正常加载。

这是我的代码

public class LogInFragment extends Fragment {

private static final String AUTHURL = "https://api.instagram.com/oauth/authorize/";

public static String CALLBACKURL = "https://www.google.com";

private static final String CLIENT_ID = "02c86b5fe4a648a0a6a47966a7bac9cb";

public LogInFragment() {
    // TODO Auto-generated constructor stub
    Log.d("LogInFragment", "Fragment Created");
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_login, container, false);
    Log.d("LogInFragment", "In onCreateView");
    String auth_URL = AUTHURL + "?client_id="+CLIENT_ID+"&redirect_uri="+CALLBACKURL+"&response_type=code";

    WebView loginView = (WebView) view.findViewById(R.id.loginWV);
    loginView.setWebViewClient(new authWebViewClient());
    loginView.loadUrl(auth_URL);
    Log.d("LogInFragment", auth_URL);
    return view;
}

private class authWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // TODO Auto-generated method stub
        if (url.startsWith(CALLBACKURL)) {
            Log.d("LogInFragment", "CALLBACK called");
            Intent intent = new Intent(getActivity(),MainActivity.class);
            String[] urlPart = url.split("=");
            String code = urlPart[1];
            intent.putExtra("code", code);
            startActivity(intent);
        }
        Log.d("LogInFragment", "CALLBACK notcalled");
        return true;
    }
}

【问题讨论】:

    标签: android webview instagram


    【解决方案1】:

    也许您需要启用 javascript:

    loginView.getSettings().setJavaScriptEnabled(true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-27
      • 1970-01-01
      相关资源
      最近更新 更多