1

I am facing a problem on android openFileChooser method. It is working well if installing via adb to a phone (samsung galaxy s3 with android 4.0.3) by using eclipse. However, if I export a signed apk from ecplise and install it into my phone, the openFileChooser method will be not calling out.

My html code:

input type='file' name='files[]' multiple accept='image/*'

My code in eclipse:

private class mainWebChromeClient extends WebChromeClient {

         @SuppressWarnings("unused")
         public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            openFileChooser(uploadMsg);
         }

         @SuppressWarnings("unused")
         public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
            openFileChooser(uploadMsg);
         }

         public void openFileChooser(ValueCallback<Uri> uploadMsg) {

                final List<Intent> cameraIntents = new ArrayList<Intent>();
                final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                File externalDataDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                File cameraDataDir = new File(externalDataDir.getAbsolutePath()+File.separator+"vast_manager_camera");
                if(!cameraDataDir.exists()){
                    cameraDataDir.mkdirs();
                }

                filePath = cameraDataDir.getAbsolutePath()+File.separator+System.currentTimeMillis()+".jpg";
                Uri imageUri = Uri.fromFile(new File(filePath));

                final PackageManager packageManager = getPackageManager();
                final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);

                final Intent intent = new Intent(captureIntent);

                for(ResolveInfo res : listCam) {
                    final String packageName = res.activityInfo.packageName;
                    intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
                    intent.setPackage(packageName);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                    cameraIntents.add(intent);

                }


                VastActivity.mUploadMessage = uploadMsg;

                Intent i = new Intent(Intent.ACTION_GET_CONTENT);

                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("image/*");               
                Intent chooserIntent = Intent.createChooser(i,"Image Chooser");

                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));
                VastActivity.this.startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);

         }
 }

I have struggle on this problem few days, but no idea to solve it (T.T), anyone please help me to solve it.

leppie
  • 115,091
  • 17
  • 196
  • 297

2 Answers2

1

If you've used proguard then the method "openFileChooser" might be somewhat obfuscated, try to add

-keep class * extends android.webkit.*

to your proguard config and see if it helps :)

1

I had the same problem. Adding this to my proguard-project.txt file fixed it for me:

-keepclassmembers class * {
    public void openFileChooser(android.webkit.ValueCallback,java.lang.String);
    public void openFileChooser(android.webkit.ValueCallback);
    public void openFileChooser(android.webkit.ValueCallback, java.lang.String, java.lang.String);
}