无法在真实设备上的webview android中查看图像和内容页面

时间:2017-05-28 03:34:57

标签: android webview

我用WebView编写了一个应用程序。我的问题是页面无法在真实设备中加载。当我在模拟器上运行时,该页面可以看到所有图像和内容。我的代码如下所示。

我的活动

public class MyActivity extends AppCompatActivity {
private WebView myWebView;
private static final String TAG = "TaoBao";
//private ProgressDialog progressDialog;
FloatingActionMenu materialDesignFAM;
FloatingActionButton floatingActionButton1, floatingActionButton2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.web_view);

    // webview
     myWebView = (WebView) findViewById(R.id.activity_webview);
    final WebSettings webSettings = myWebView.getSettings();
    //webSettings.setSupportMultipleWindows(true);
    //webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    myWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    if (Build.VERSION.SDK_INT >= 21) {
        webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }

    webSettings.setJavaScriptEnabled(true);
    // set javascript and zoom and some other settings
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setAppCacheEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    myWebView.getSettings().setAllowFileAccess(true);
    myWebView.getSettings().setAllowContentAccess(true);
    myWebView.setScrollbarFadingEnabled(false);
    // enable all plugins (flash)
    webSettings.setPluginState(WebSettings.PluginState.ON);



    // Floating Menu
    materialDesignFAM = (FloatingActionMenu) findViewById(R.id.material_design_android_floating_action_menu);
    floatingActionButton1 = (FloatingActionButton) findViewById(R.id.material_design_floating_action_menu_item1);
    floatingActionButton2 = (FloatingActionButton) findViewById(R.id.material_design_floating_action_menu_item2);


    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    final ACProgressFlower progressDialog = new ACProgressFlower.Builder(this)
            .direction(ACProgressConstant.DIRECT_CLOCKWISE)
            .themeColor(Color.WHITE)
            .text("Loading...")
            .fadeColor(Color.DKGRAY).build();
    progressDialog.show();

    myWebView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.i(TAG, "Processing webview url click...");
           // if( URLUtil.isNetworkUrl(url) ) {
            //    return false;
           // }
           // if (appInstalledOrNot(url)) {
           //     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
           //     startActivity( intent );
            //} else {
                // do something if app is not installed
           // }
          //  return true;

            view.loadUrl(url);
            return false;

        }


        public void onPageFinished(WebView view, String url) {
            Log.i(TAG, "Finished loading URL: " + url);
            super.onPageFinished(view, url);
            if (progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
        }

        public void onReceivedError(WebView webView, int errorCode, String description, String failingUrl) {
            try {
                webView.stopLoading();
            } catch (Exception e) {
            }

            if (webView.canGoBack()) {
                webView.goBack();
            }

            webView.loadUrl("about:blank");
            AlertDialog alertDialog = new AlertDialog.Builder(TaoBao.this).create();
            alertDialog.setTitle("Error");
            alertDialog.setMessage("Check your internet connection and try again.");
            alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Try Again", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                    startActivity(getIntent());
                }
            });

            alertDialog.show();
            super.onReceivedError(webView, errorCode, description, failingUrl);
        }
    });

    myWebView.loadUrl("https://m.intl.taobao.com/");

}

@Override
public void onBackPressed() {
    if (myWebView.canGoBack()) {
        myWebView.goBack();
    } else {
        super.onBackPressed();
    }
}enter code here

main_activity.xml

`       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            xmlns:fab="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <WebView
                android:id="@+id/activity_webview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />

        </RelativeLayout>`

`这是我的截图

在Real Device Android 4.3上测试 enter image description here

在模拟器Android 4.3上测试 enter image description here

在真实设备上无法从网络上看到任何照片和内容。但在模拟器上可以看到图像和内容。如何修复它可以在真实设备上看到图像和内容?请帮我。 最好的祝福, STP

1 个答案:

答案 0 :(得分:0)

你的真手机可能是android 7.0吗?