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.