如何从android上的本地或外部存储获取的任何文件中获取路径?这是我的代码:
Intent = new Intent(Intent.ActionOpenDocument);
string[] mimetypes =
{
"application/pdf", "image/png", "image/jpeg", "image/tiff", "application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
};
Intent.PutExtra(Intent.ExtraMimeTypes, mimetypes);
Intent.SetType("*/*");
Intent.SetAction(Intent.ActionGetContent);
Intent.AddCategory(Intent.CategoryOpenable);
StartActivityForResult(Intent.CreateChooser(Intent, "Select file"), Constant.PickPDFId);
我得到的OnActivityResults:
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == Constant.PickPDFId && resultCode == Result.Ok && data != null)
{
var FilePath= data.Data.Path;
}
FilePath在' document / 3137-3837:Screenshots / Screenshot_2018.png 之间有一个冒号。如何在没有冒号的情况下获得有效路径?
答案 0 :(得分:0)
您在此处检索的文件路径:
var FilePath= data.Data.Path;
只是一个URI,您需要将其转换为实际的文件路径,但由于您要返回varius MIME类型,因此需要以不同方式处理URI,