0
public void onActivityResult(int requestCode, int resultCode, Intent data) {

switch (requestCode) {
    case REQUEST_CHOOSER:   
        if (resultCode == Activity.RESULT_OK) {

            final Uri uri = data.getData();

            // Get the File path from the Uri
            String path = FileUtils.getPath(this, uri);

            // Alternatively, use FileUtils.getFile(Context, Uri)
            if (path != null && FileUtils.isLocal(path)) {
                File file = new File(path);
            }
        }
        break;
     }
   }

我从 github 复制这段代码,这个链接https://github.com/iPaulPro/aFileChooser ,我把这段代码放在一个片段中。在这一行中,它显示错误

 String path = FileUtils.getPath(this, uri);

显示此错误:

The method getPath(Context, Uri) in the type FileUtils is not applicable for the arguments (PagesFragment, Uri)

任何人都可以帮我解决这个问题吗?

4

1 回答 1

3

试试这样

 public void onActivityResult(int requestCode, int resultCode, Intent data) {

    switch (requestCode) {
        case REQUEST_CHOOSER:   
            if (resultCode == Activity.RESULT_OK) {

                final Uri uri = data.getData();

                // Get the File path from the Uri
                String path = FileUtils.getPath(getActivity(), uri);

                // Alternatively, use FileUtils.getFile(Context, Uri)
                if (path != null && FileUtils.isLocal(path)) {
                    File file = new File(path);
                }
            }
            break;
         }
       }
于 2014-10-31T12:19:02.593 回答