android openfilechooser没有显示Android版本低于3.0的录音机

时间:2013-07-05 08:24:39

标签: android

我想在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选择器的设备版本显示选项两次。如果你有任何问题,建议解决这个问题。

1 个答案:

答案 0 :(得分:0)

这个烦人的未记录的功能已经改变了原型几次。当我们想要支持文件上传时,我们使用此代码:

// For Android 4.1+
public void openFileChooser(ValueCallback<Uri> uploadFileCallback, String acceptType, String capture) {
    Log.i(TAG, "Opening file chooser for type '" + acceptType + "', capture '" + capture + "'");
    // Add your file picker code here!
}

// For Android 3.0+
public void openFileChooser(ValueCallback<Uri> uploadFileCallback, String acceptType) {
    Log.i(TAG, "Opening legacy file chooser for type '" + acceptType + "'");
    openFileChooser(uploadFileCallback, acceptType, "");
}

// For Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadFileCallback) {
    Log.i(TAG, "Opening very legacy file chooser");
    openFileChooser(uploadFileCallback, "");
}