Webview does not allow me to select image

2

I have a hybrid app that works through a webview. I have solved the theme of pop-ups for the login of facebook or twitter. However, when you click on the < input type="file" / > nothing opens. I do not understand why. Can someone tell me if there is any way to open an input file to choose and upload an image from the webview?

Note: The website is in php, the webview only shows it and the app does not do anything more than that.

    
asked by Criss 17.06.2016 в 16:56
source

1 answer

1

The problem in this type of, specifically input.file is that due to Security does not allow its operation, it simply will not recognize it.

If you want to do something similar it would be implementing WebChromeClient () , this is an example:

link

public class MyAwesomeActivity extends Activity {

 private WebView wv;

 private ValueCallback<Uri> mUploadMessage;
 private final static int FILECHOOSER_RESULTCODE=1;

 @Override
 protected void onActivityResult(int requestCode, int resultCode,
                                    Intent intent) {
  if(requestCode==FILECHOOSER_RESULTCODE)
  {
   if (null == mUploadMessage) return;
            Uri result = intent == null || resultCode != RESULT_OK ? null
                    : intent.getData();
            mUploadMessage.onReceiveValue(result);
            mUploadMessage = null;

  }
 }

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

  wv = new WebView(this);
  wv.setWebViewClient(new WebViewClient());
  wv.setWebChromeClient(new WebChromeClient()
  {
         //The undocumented magic method override
         //Eclipse will swear at you if you try to put @Override here
         public void openFileChooser(ValueCallback<Uri> uploadMsg) {

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

         }
  });

  setContentView(wv);
 }
    
answered by 17.06.2016 в 18:20