android openfilechooser方法没有调用签名的apk

时间:2014-03-25 14:14:34

标签: android apk signed

我在android openFileChooser方法上遇到问题。如果通过使用eclipse通过adb安装到手机(带有android 4.0.3的samsung galaxy s3),它运行良好。但是,如果我从ecplise导出签名的apk并将其安装到我的手机中,则openFileChooser方法将不会调用。

我的HTML代码:

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

我在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);

         }
 }

我几天都在努力解决这个问题,但不知道解决它(T.T),有人请帮我解决。

2 个答案:

答案 0 :(得分:1)

如果您使用过proguard,那么方法“openFileChooser”可能会有些混淆,尝试添加

-keep class * extends android.webkit。*

到你的proguard配置,看它是否有帮助:)

答案 1 :(得分:1)

我遇到了同样的问题。将它添加到我的proguard-project.txt文件中为我修复了它:

-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);
}