Android Webview未知错误

时间:2014-03-27 10:51:42

标签: android webview android-logcat

我制作了一款使用WebView的应用。但是,LogCat会产生此错误:

03-27 10:36:35.830: E/eglCodecCommon(1466): **** ERROR unknown type 0x0 (glSizeof,73)

我知道0x0是一种未知的错误类型(在Linux命令中),但我该如何解决这个问题呢? 我的Java代码是:

@SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    private WebView edlineWebView;
    private ProgressBar progressBar1;
    private String currentUrl;
    private boolean exitConfirmation;
    private BroadcastReceiver completeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Resources res = context.getResources();
            Toast.makeText(context, res.getString(R.string.download_complete), Toast.LENGTH_SHORT).show();
            startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));
        }
    };

    final Activity activity = this;

    @Override
    public void onBackPressed() {
        if (edlineWebView.copyBackForwardList().getCurrentIndex() > 0) {
            edlineWebView.goBack();
        }    
        else {
            if (exitConfirmation) {
                super.onBackPressed();
                return;
            }

            this.exitConfirmation = true;
            Toast.makeText(this, "Press the back key again to exit", Toast.LENGTH_SHORT).show();

            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    exitConfirmation=false;                       
                }
            }, 2000);
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.activity_main);

        edlineWebView = (WebView) findViewById(R.id.webView1); 
        progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);
        String url = "http://www.edline.net/";

        edlineWebView.setWebViewClient(new WebViewClient());
        edlineWebView.getSettings().setJavaScriptEnabled(true);
        edlineWebView.getSettings().setUserAgentString("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");
        edlineWebView.loadUrl(url);
        edlineWebView.setDownloadListener(new DownloadListener() {
            @SuppressLint("DefaultLocale")
            @Override
            public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
                MimeTypeMap mtm = MimeTypeMap.getSingleton();
                DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
                Uri downloadUri = Uri.parse(url);
                String fileName = downloadUri.getLastPathSegment();
                int pos = 0;

                if ((pos = contentDisposition.toLowerCase().lastIndexOf("filename=")) >= 0) {
                    fileName = contentDisposition.substring(pos + 9);
                    pos = fileName.lastIndexOf(";");
                    if (pos > 0) {
                        fileName = fileName.substring(0, pos - 1);
                    }
                }

                String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()).toLowerCase();
                String mimeType = mtm.getMimeTypeFromExtension(fileExtension);
                Request request = new DownloadManager.Request(downloadUri);
                request.setTitle(fileName);
                request.setDescription(url);
                request.setMimeType(mimeType);  
                request.setDestinationInExternalPublicDir( Environment.DIRECTORY_DOWNLOADS, fileName);
                Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOWNLOADS).mkdirs();
                downloadManager.enqueue(request);
            }
        });

        currentUrl = url;
        edlineWebView.setWebChromeClient(new WebChromeClient() 
        {  
            public void onProgressChanged(WebView view, int progress) 
            {  
                if (progress<100)
                {
                    progressBar1.setVisibility(ProgressBar.VISIBLE);
                }
                else if (progress==100)
                {
                    progressBar1.setVisibility(ProgressBar.GONE);              
                }
                progressBar1.setProgress(progress);  
            }
        });

        edlineWebView.setWebViewClient(new WebViewClient() 
        {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                currentUrl = edlineWebView.getUrl();
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                view.loadUrl(url);
                return true;
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        unregisterReceiver(completeReceiver);
    }

    @Override
    protected void onResume() {
        IntentFilter completeFilter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
        registerReceiver(completeReceiver, completeFilter);
        super.onResume();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {
        case R.id.goto_browser:
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(currentUrl));
            startActivity(i);

            return true;
        }
        return false;
    }
}

1 个答案:

答案 0 :(得分:9)

就我而言,我加载了一个包含图像滑块的网站。当滑块更改图像时,logcat会生成相同的错误代码。我认为这种情况发生了,因为网页会计算我设备屏幕的大小。我只是在猜测,因为它来自gl:

05-03 10:15:25.149: E/eglCodecCommon(5081): **** ERROR unknown type 0x1 (glSizeof,73)