1

Im trying to use webview to upload a image. My gallery gets displayed but when i click a image it crashes my app... then when i reopen my app it just gives me a white screen until i reupload my app on my phone again. Im confused and hit a roadblock on how to fix this.

 web = (WebView) findViewById(R.id.webView1);
    progressBar = (ProgressBar) findViewById(R.id.progressBar1);

    web = new WebView(this);  
    web.getSettings().setJavaScriptEnabled(true);
    web.loadUrl("http://.com");
    web.setWebViewClient(new myWebClient());
    web.setWebChromeClient(new WebChromeClient()   
    {  
           //The undocumented magic method override  
           //Eclipse will swear at you if you try to put @Override here  
        // For Android 3.0+
        public void openFileChooser(ValueCallback<Uri> uploadMsg) {  

            mUploadMessage = uploadMsg;  
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
            i.addCategory(Intent.CATEGORY_OPENABLE);  
            i.setType("image/*");  
            MainMenu.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);  

           }

        // For Android 3.0+
           public void openFileChooser( ValueCallback uploadMsg, String acceptType ) {
           mUploadMessage = uploadMsg;
           Intent i = new Intent(Intent.ACTION_GET_CONTENT);
           i.addCategory(Intent.CATEGORY_OPENABLE);
           i.setType("*/*");
           MainMenu.this.startActivityForResult(
           Intent.createChooser(i, "File Browser"),
           FILECHOOSER_RESULTCODE);
           }

        //For Android 4.1
           public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
               mUploadMessage = uploadMsg;  
               Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
               i.addCategory(Intent.CATEGORY_OPENABLE);  
               i.setType("image/*");  
               MainMenu.this.startActivityForResult( Intent.createChooser( i, "File Chooser" ), MainMenu.FILECHOOSER_RESULTCODE );

           }

    });  


    setContentView(web);  


}


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

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // TODO Auto-generated method stub

        view.loadUrl(url);
        return true;

    }

    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);

        progressBar.setVisibility(View.GONE);
    }
}

//flipscreen not loading again
@Override
public void onConfigurationChanged(Configuration newConfig){        
    super.onConfigurationChanged(newConfig);
}

// To handle "Back" key press event for WebView to go back to previous screen.
/*@Override
public boolean onKeyDown(int keyCode, KeyEvent event) 
{
    if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
        web.goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}*/






@Override
public void onDestroy() {
  if (adView != null) {
    adView.destroy();
  }
  super.onDestroy();
}


//    public void onBackPressed()  
//    {
//        if(mWebView.canGoBack())
//            mWebView.goBack();
 //        else{
//            Intent start = new Intent(MainMenu.this,MainMenu.class);
//        startActivity(start);
//        finish();    }}



}
user2423476
  • 2,115
  • 8
  • 28
  • 40
  • I think `web = (WebView) findViewById(R.id.webView1);` is enough. ` web = new WebView(this);` is not needed. Post the logcat to trace error. – Nizam Aug 30 '13 at 09:32
  • I need my phone disconnected from my computer to select an image... Dont know how i can get the logcat error – user2423476 Aug 30 '13 at 09:37
  • Have a look at http://stackoverflow.com/questions/14419191/save-app-event-logcat-in-file-on-sd – Nizam Sep 03 '13 at 08:01

0 Answers0