3

So I have a custom webView that seems to work fine accept for one url that is needed for my app. I have tested the same url in the native browser of the tablet and it loads fine, but in my custom web view it hangs on loading forever. other urls are working fine with my webview just this one. I have my webSetting set to allow plugins, so i don't think that is the problem. I have noticed that the screen starts to undimm like the page is loaded and then goes dimm again immediately.

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 the normal browser...

Darpan
  • 5,623
  • 3
  • 48
  • 80
erik
  • 4,946
  • 13
  • 70
  • 120
  • I have the same problem and was thinking of asking it but no help. Try sharing it or a bounty may be.. It will help. – Darpan Dec 06 '12 at 12:19
  • My problem was actually do to a redirect the page was firingthat never triggered the p varrogress complete. I solved it with an int – erik Dec 06 '12 at 21:20
  • what did you do exactly ?can u elaborate? i am facing the same issue. Thanks. – Ryhot Jan 27 '14 at 13:03

0 Answers0