2013-05-24 2 views
0

일부 웹 페이지를 표시하는 webview가 있습니다. 웹 페이지에 iframe이있어 사용자가 사진을 선택하고 업로드 할 수 있습니다. 내 문제는 단추를 클릭하고 사진을 선택하면 onActivityResult 메서드가 끝난 후 iframe 페이지 대신 전체 주 페이지가 새로 고쳐집니다. iframe 페이지 만 새로 고칠 수 있습니까?android webview iframe에서 제출

메인 페이지

<iframe scrolling="no" src="/service/ccrp.do?method=img"></iframe> 
<img id="uploadImg" name="uploadImg" src="" style="display: none;"/> 
<input type="hidden" id="imgUrl" name="imgUrl" /> 

iframe이 페이지 (/service/ccrp.do?method=img)

function sub() { 
     var path = $("#file").val(); 
     var fs = path.split("\\"); 
     var fileName = fs[fs.length - 1]; 
     $("#file_form")[0].submit(); 
    } 
<form id="file_form" onsubmit="return false;" 
      ENCTYPE="multipart/form-data" method="post" 
      action="/module/bbs/mobile.do?method=upload"> 
<input id="file" name="file" type="file" onchange="sub()"> 
</form> 

WebviewActivity 해결

@Override 
protected void onStart() { 
    // TODO Auto-generated method stub 
    super.onStart(); 
    initWebview(); 
} 

private void initWebview(){ 
    WebSettings settings = webview1.getSettings(); 
    settings.setAllowFileAccess(true); 
    settings.setJavaScriptEnabled(true); 
    webview1.setWebViewClient(new WebViewClient() { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      view.loadUrl(url); 
      return true; 
     } 
    } 
    webview1.setWebChromeClient(new WebChromeClient() { 
     // For Android 4+ 
     public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){ 
      openFileChooser(uploadMsg); 
     } 
     // For Android 3.0+ 
     public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) 
     { 
     openFileChooser(uploadMsg); 
     } 

     // For Android < 3.0 
     public void openFileChooser(ValueCallback<Uri> uploadMsg) 
     { 
      WebviewActivity.this.mUploadMessage = uploadMsg; 
      Intent i = new Intent(Intent.ACTION_GET_CONTENT); 
      i.addCategory(Intent.CATEGORY_OPENABLE); 
      i.setType("image/*"); 
      WebviewActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); 
     } 
    }); 
    webview1.loadUrl(url); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, 
     Intent intent) { 

    switch (requestCode) { 

    // Choose a file from the file picker. 
    case FILECHOOSER_RESULTCODE: 
     if (null == mUploadMessage) 
      break; 
     Uri result = intent == null || resultCode != RESULT_OK ? null 
       : intent.getData(); 
     Log.v("CEEG_RESULT", "onActivityResult:" + result.getQuery()); 
     mUploadMessage.onReceiveValue(result); 
     mUploadMessage = null; 
     break; 
    } 
} 

답변

0

. onCreate 대신에 onStart에 initWebview 메소드를 잘못 넣었습니다. 그래서 html 링크를 클릭하면 onStart가 다시 한번 트리거되고 iframe 양식을 제출하지 않고 mainpage URL을 다시로드합니다.