我的应用因未实现的webview api而崩溃(请在标记重复或投反对票之前阅读完整说明)

时间:2018-07-03 18:36:13

标签: android webview crash onkeydown

在我的logcat中,我发现错误日志为:

UnimplementedWebViewApi                      Unimplemented WebView method onKeyDown called from: android.webkit.WebView.onKeyDown(WebView.java:2191)

我的secondActivity.java

`

    package com.msqenterprises.assistant;
import android.app.*;
import android.os.*;
import android.webkit.*;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.*;
import android.graphics.*;
import android.view.*;
import android.view.KeyEvent;
import java.security.*;

public class secondActivity extends Activity
{
    WebView wv;
    ProgressBar loader;

    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);

        wv = (WebView) findViewById(R.id.wv);
        loader = (ProgressBar) findViewById(R.id.loader);

        try{
        Bundle extras = getIntent().getExtras();
        String loadInWebView = extras.getString("GO");

        wv.getSettings().setAllowContentAccess(true);
        wv.getSettings().setAllowFileAccess(true);
        wv.getSettings().setAllowFileAccessFromFileURLs(true);
        wv.getSettings().setAppCacheEnabled(true);
        wv.getSettings().setBuiltInZoomControls(true);
        wv.getSettings().setDatabaseEnabled(true);
        wv.getSettings().setDisplayZoomControls(true);
        wv.getSettings().setDomStorageEnabled(true);
        wv.getSettings().setEnableSmoothTransition(true);
        wv.getSettings().setGeolocationEnabled(true);
        wv.getSettings().setJavaScriptEnabled(true);
        wv.getSettings().setSaveFormData(true);
        wv.getSettings().setSupportZoom(true);
        wv.getSettings().setUseWideViewPort(true);
        wv.loadUrl(loadInWebView);
        wv.setWebViewClient(new WebClient());
        }
        catch(Exception e){}

    }

    public class WebClient extends WebViewClient
    {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            // TODO: Implement this method
            view.loadUrl(url);

            return super.shouldOverrideUrlLoading(view, url);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon)
        {
            // TODO: Implement this method
            super.onPageStarted(view, url, favicon);
            wv.setVisibility(View.GONE);
            loader.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url)
        {
            // TODO: Implement this method
            super.onPageFinished(view, url);

            wv.setVisibility(View.VISIBLE);
            loader.setVisibility(View.GONE);
        }



    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        // TODO: Implement this method

        try{
        if((keyCode == KeyEvent.KEYCODE_BACK) && wv!=null && wv.canGoBack()){
            wv.goBack();
            return true;
        }
        }
        catch(Exception e){}

        return super.onKeyDown(keyCode, event);
    }

    /*

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        // TODO: Implement this method

        if(event.getAction() == KeyEvent.ACTION_DOWN){
            switch(keyCode){
                case KeyEvent.KEYCODE_BACK:
                    if(wv.canGoBack()){
                        wv.goBack();
                        return true;
                    }
                    else{
                        finish();
                        return true;
                    }

            }
        }
        //return true;
        return super.onKeyDown(keyCode, event);
    }

    */



} `

MainActivity.java

` @Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    // TODO: Implement this method
    if(event.getAction() == KeyEvent.ACTION_DOWN){

        switch(keyCode){
            case KeyEvent.KEYCODE_BACK:
                //Toast.makeText(getApplicationContext(), "Press Again to Exit App", Toast.LENGTH_SHORT).show();
                AlertDialog exitDialog = new AlertDialog.Builder(this).create();
                exitDialog.setTitle("Exit App!");
                exitDialog.setCancelable(false);
                exitDialog.setMessage("Are you sure to exit?");
                exitDialog.setButton("No", new DialogInterface.OnClickListener(){
                    public void onClick(DialogInterface dialogExitNo, int status){
                        dialogExitNo.dismiss();
                        return true;
                    }
                });
                exitDialog.setButton2("Yes", new DialogInterface.OnClickListener(){
                    public void onClick(DialogInterface dialogExitYes, int status){
                        finish();
                        return true;
                    }
                });

        }

    }


    return super.onKeyDown(keyCode, event);
} `

我不知道为什么它崩溃,当我运行并安装它时,会崩溃,不幸的是,助手已停止对话框消息。

我以前从未遇到过这样的错误,也从未听说过,今天(2018年7月2日上午10:48)发生在我身上,当时我在按钮的if else方法中添加了更多数据。

android.permission.INTERNET也作为使用Webview的权限添加在AndroidManifest.xml中。

但是我的logcat却什么都没有显示,只是空白,并要求运行该项目,但是即使每次询问都在运行项目之后也没有记录日志。

请帮助大家

0 个答案:

没有答案