【问题标题】:android openfilechooser method not calling on signed apkandroid openfilechooser方法没有调用签名的apk
【发布时间】:2014-03-25 14:14:33
【问题描述】:

我在使用 android openFileChooser 方法时遇到问题。如果使用 eclipse 通过 adb 安装到手机(带有 android 4.0.3 的三星 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),请任何人帮我解决它。

【问题讨论】:

    标签: android apk signed


    【解决方案1】:

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

    -keep class * 扩展 android.webkit.*

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

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。将此添加到我的 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);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-08-02
        • 2017-01-15
        • 1970-01-01
        • 2021-10-10
        • 2020-12-16
        • 2012-10-03
        • 2017-11-20
        • 1970-01-01
        相关资源
        最近更新 更多