我想在 webview 中上传文件。当我单击 android 版本高于 3.0 的设备的选择按钮时,选择器中没有显示录音机选项。这是我的代码
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
String path = Environment.getExternalStorageDirectory().toString();
File file = new File(path, "temp.jpg");
file.delete();
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
Intent openInChooser=Intent.createChooser(i,"File Chooser");
Intent value[]=new Intent[2];
value[0]= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
value[0].addCategory(Intent.CATEGORY_OPENABLE);
Intent fileExplorer= new Intent(MainActivity.this,DirectoryBrowser.class);
fileExplorer.setComponent(new ComponentName(MainActivity.this, DirectoryBrowser.class));
value[1] = new LabeledIntent(fileExplorer, "com.app.insta7", "File Explorer", R.drawable.folder);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, value);
MainActivity.this.startActivityForResult(openInChooser, FILECHOOSER_RESULTCODE);
}
如果我添加这一行并将意图数组大小增加到 3
value[2] = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
对于版本低于 3.0 的设备,选择器显示选项两次。如果您有任何问题,请建议解决此问题。