3

所以我有一个自定义的 webView 似乎可以很好地接受我的应用程序所需的一个 url。我已经在平板电脑的本机浏览器中测试了相同的 url,它加载正常,但在我的自定义 web 视图中,它永远挂在加载中。其他 url 在我的 webview 上运行良好,只是这个。我的 webSetting 设置为允许插件,所以我认为这不是问题。我注意到屏幕开始变暗,就像页面加载一样,然后立即再次变暗。

我的网络视图:

public class Browser extends Activity {

    private WebView wv;

    private ProgressDialog progressBar;

    private static final String TAG = "Browser";

    private SharedPreferences prefs;
    private String prefName = Constants.prefName;

    private static final String TABLET_TYPE_KEY = Constants.TABLET_TYPE_KEY;
    private String tabletType;  

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     


        prefs = getSharedPreferences(prefName, MODE_PRIVATE);

        tabletType = prefs.getString(TABLET_TYPE_KEY, "");

        boolean customerTablet = false;
        boolean associateTablet = false;
        boolean doctorTablet = false;
        boolean doctorDoctorTablet = false;

        if(tabletType.equals("Associate")) {
            associateTablet = true;
        }


        //--- FULLSCREEN ---
        requestWindowFeature(Window.FEATURE_NO_TITLE); 
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                       WindowManager.LayoutParams.FLAG_FULLSCREEN);         
        //--- FULLSCREEN ---


        //this.getWindow().requestFeature(Window.FEATURE_PROGRESS);

        String url = "";
        String navtype = "";
        Bundle extras = getIntent().getExtras();
        if(extras != null) {
            url = extras.getString("url");
            navtype = extras.getString("navtype");
        }

        if(navtype.equals("nonav")) {
            setContentView(R.layout.browsernonav);
        }
        else {
            setContentView(R.layout.browser);
        }



        //WebView wv = (WebView) findViewById(R.id.webview1);
        wv = (WebView) findViewById(R.id.webview1);
        wv.setWebViewClient(new Callback());
        WebSettings webSettings = wv.getSettings();
        webSettings.setBuiltInZoomControls(true);
        webSettings.setJavaScriptEnabled(true);

        webSettings.setAppCacheEnabled(true);

        webSettings.setPluginsEnabled(true);
        webSettings.setPluginState(WebSettings.PluginState.ON);

        // Zoom only on 7 inch tablet
        if(associateTablet) webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);        

        wv.addJavascriptInterface(new JavaScriptInterface(this), "Android");

        progressBar = ProgressDialog.show(Browser.this, "", "Loading...");

        final Browser MyActivity = this;



        if(!navtype.equals("nonav")) {
            final ImageView btn_back = (ImageView) findViewById(R.id.btn_back);
            btn_back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    // Perform action on clicks
                    wv.goBack();
                }
            });      

            final ImageView btn_forward = (ImageView) findViewById(R.id.btn_forward);
            btn_forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    // Perform action on clicks
                    wv.goForward();
                }
            });
        }


        wv.loadUrl(url);

        //wv.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);                         

    }

    /*
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            // close image gallery
            wv.goBack();
            return false; // this avoids passing to super
        }

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

    private class Callback extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return(true);
        }
        @Override
        public void onPageFinished(WebView view, String url) {
            Log.i(TAG, "Finished loading URL: " +url);
            if (progressBar.isShowing()) {
                progressBar.dismiss();
            }
        }

        @Override
        public void onPageStarted (WebView view, String url, Bitmap favicon) {
            progressBar = ProgressDialog.show(Browser.this, "", "Loading...");
        }

    }


    public class JavaScriptInterface {
        Context mContext;

        /** Instantiate the interface and set the context */
        JavaScriptInterface(Context c) {
            mContext = c;
        }

        /** Show a toast from the web page */
        public void spawnPrintJob() {
            Uri uri = Uri.parse("file:///sdcard/medical_form.html");
            //Uri uri = Uri.parse("http://www.cnn.com");

            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setPackage("com.dynamixsoftware.printershare");                   
            i.setDataAndType(uri, "text/html");
            //i.setDataAndType(uri, "image/jpeg");
            startActivity(i);                   

        }

        public void deleteForm() {
            //Toast.makeText(mContext, "Temp", Toast.LENGTH_SHORT).show();
            File sdCard = Environment.getExternalStorageDirectory();

            File[] toBeDeleted = sdCard.listFiles(new FileFilter() {  
                public boolean accept(File theFile) {  
                    if (theFile.isFile()) {  
                        return theFile.getName().endsWith(".html");  
                    }  
                        return false;  
                }  
            });  

            //System.out.println(Arrays.toString(toBeDeleted));  
            for(File deletableFile:toBeDeleted){  
                deletableFile.delete();  
            }                       
        }

    }



}

网址再次在普通浏览器中加载正常......

4

0 回答 0