Web browsing freezes when native browser is not

So I have a custom webView that seems to be great for the single url that is needed for my application. I tested the same URL in my tablet’s native browser and it loads fine, but in my user web view it freezes when it downloads forever. other urls work fine with my webview. I have a webSetting suite for plugins, so I don't think this is a problem. I noticed that the screen starts to spin up as soon as the page loads, and then immediately disappears.

my webview:

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();  
            }                       
        }

    }



}

again the url loads fine in a normal browser ...

+3
source share

All Articles