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,I将此代码放入片段中。在此行中,它显示错误
String path = FileUtils.getPath(this, uri);
显示此错误:
The method getPath(Context, Uri) in the type FileUtils is not applicable for the arguments (PagesFragment, Uri)
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:2)
尝试这样,
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;
}
}