2016-11-21 8 views
0

ベローは私のWebViewの設定は次のとおりです。のWebViewいいえ「アクセス制御 - 許可 - 起源」ヘッダが存在[アンドロイド]で

webView = (WebView) findViewById(R.id.webview); 

//  webView.clearHistory(); 
//  webView.getSettings().setLoadWithOverviewMode(true); 
//  webView.getSettings().setUseWideViewPort(true); 
//  webView.getSettings().setBuiltInZoomControls(true); 
//  webView.getSettings().setDomStorageEnabled(true); 
//  if (android.os.Build.VERSION.SDK_INT >= 16) 
//  { 
//   webView.enablecrossdomain41(); 
// 
//   webView.getSettings().setAllowUniversalAccessFromFileURLs(true); 
//   webView.getSettings().setAllowFileAccessFromFileURLs(true); 
// 
//  } 
//  else 
//  { 
//   webView.enablecrossdomain(); 
//  } 


    if (Build.VERSION.SDK_INT >= 16) { 
     webView.getSettings().setAllowUniversalAccessFromFileURLs(true); 
     webView.getSettings().setAllowFileAccessFromFileURLs(true); 
    }else{ 
     Class<?> clazz = webView.getSettings().getClass(); 
     Method method = null; 
     try { 
      method = clazz.getMethod("setAllowUniversalAccessFromFileURLs", boolean.class); 
      if (method != null) { 
       method.invoke(webView.getSettings(), true); 
      } 
      method = clazz.getMethod("setAllowFileAccessFromFileURLs", boolean.class); 
      if (method != null) { 
       method.invoke(webView.getSettings(), true); 
      } 
     } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { 
      e.printStackTrace(); 
     } 

    } 
    webView.setWebViewClient(new MyWebViewClient()); 
    webView.getSettings().setLoadWithOverviewMode(true); 
    webView.getSettings().setJavaScriptEnabled(true); 

//  if (Build.VERSION.SDK_INT >= 11) { 
//   webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 
// 

} 

    webView.loadUrl("http://jobs.bdjobs.com/jobdetails.asp?id=675496&fcatId=-1&ln=1"); 

ベローは私MyWebViewClientコードです:

private class MyWebViewClient extends WebViewClient { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { 
      view.loadUrl(request.getUrl().toString()); 
      return true; 
     } 

     @Override 
     public void onPageFinished(WebView view, String url) { 
      progress.setVisibility(View.GONE); 
      tv.setVisibility(View.GONE); 
      WebActActivity.this.progress.setProgress(100); 
      webView.setVisibility(View.VISIBLE); 
      super.onPageFinished(view, url); 
     } 

     @Override 
     public void onPageStarted(WebView view, String url, Bitmap favicon) { 
      progress.setVisibility(View.VISIBLE); 
      tv.setVisibility(View.VISIBLE); 
      webView.setVisibility(View.GONE); 
      WebActActivity.this.progress.setProgress(0); 
      super.onPageStarted(view, url, favicon); 
     } 

     @Override 
     public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { 
      MyLog.e("error1", error.toString()); 
      handler.proceed(); 
     } 

     @Override 
     public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { 
      MyLog.e("error2", error.toString()); 
     } 

     @Override 
     public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
      MyLog.e("error3", description); 
      MyLog.e("error3", failingUrl); 
     } 

     @Override 
     public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) { 
      MyLog.e("error4", cancelMsg.toString()); 
      MyLog.e("error4", continueMsg.toString()); 
     } 
    } 

しかし、何も表示されませんウェブビューで私はロードしようとしているリンクがブラウザ上で完璧に動作していることを確認しました。私もこの回答しようとしている

I/ActivityManager: Displayed com.pipilika.jobsearch/.activity.WebActActivity: +233ms 
W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 25726 
I/chromium: [INFO:CONSOLE(0)] "Access to Font at 'http://www.bdjobs.com/errormessages/404.htm' from origin 'http://www.bdjobs.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://jobs.bdjobs.com' is therefore not allowed access.", source: http://jobs.bdjobs.com/jobdetails.asp?id=675496&fcatId=-1&ln=1 (0) 
E/chromium: [ERROR:interface_registry.cc(99)] Failed to locate a binder for interface: autofill::mojom::AutofillDriver 
V/FA: Inactivity, disconnecting from the service 
I/chromium: [INFO:CONSOLE(0)] "XMLHttpRequest cannot load https://fonts.googleapis.com/css?family=Montserrat:400,700. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://jobs.bdjobs.com' is therefore not allowed access. The response had HTTP status code 405.", source: http://jobs.bdjobs.com/jobdetails.asp?id=675496&fcatId=-1&ln=1 (0) 
I/chromium: [INFO:CONSOLE(0)] "XMLHttpRequest cannot load https://fonts.googleapis.com/css?family=Open+Sans:400,600. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://jobs.bdjobs.com' is therefore not allowed access. The response had HTTP status code 405.", source: http://jobs.bdjobs.com/jobdetails.asp?id=675496&fcatId=-1&ln=1 (0) 

android webview - Access-Control-Allow-Origin

をしかし、それはどちらか動作していない

コンソールがいることを述べています。私はさらに何をすることができますか?コードの下

答えて

-1

使用、

mWebview = (WebView) findViewById(R.id.mWebview); 
    mWebview.setWebViewClient(new myWebClient()); 
     mWebview.getSettings().setJavaScriptEnabled(true); 
     mWebview.setBackgroundColor(Color.parseColor("#daedf5")); 
     mWebview.loadUrl("http://jobs.bdjobs.com/jobdetails.asp?id=675496&fcatId=-1&ln=1"); 

WebViewのローダー:

/** 
* Load Webview with using Progressbar 
*/ 
public class myWebClient extends WebViewClient { 
    @Override 
    public void onPageStarted(WebView view, String url, Bitmap favicon) { 
     // TODO Auto-generated method stub 
     super.onPageStarted(view, url, favicon); 
    } 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     // TODO Auto-generated method stub 

     view.loadUrl(url); 
     return true; 

    } 

    @Override 
    public void onPageFinished(WebView view, String url) { 
     // TODO Auto-generated method stub 
     super.onPageFinished(view, url); 

     progressBar.setVisibility(View.GONE); 
    } 
} 
+0

それが動作しない場合、私は私が、それは私のために働いて、エラーが何であるかを – Vadivel

+0

あなたをお手伝いしますあなたのURLを試しました – Shoshi

+0

が動作していない – Vadivel

関連する問題