我收到错误:"上传失败。无法安排1个文件上传"。我正在尝试创建一个简单的文件资源管理器。当用户点击listView上的非文件夹项目时,会出现Google云端硬盘上传对话框,但是当我点击Google云端硬盘对话框中的“保存”按钮时出现错误。下面显示了我的编码。请告诉我我做错了什么或哪些部分。谢谢。
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Option o = adapter.getItem(position);
if(o.getData().equalsIgnoreCase("folder")||o.getData().equalsIgnoreCase("parent directory")){
currentDir = new File(o.getPath());
fill(currentDir);
}
else
{
onFileClick(o);
}
}
private void onFileClick(Option o)
{
Toast.makeText(this, "File Clicked: "+o.getName(), Toast.LENGTH_SHORT).show();
String uri = o.getPath();
Uri uploadUri = Uri.parse(uri);
Toast.makeText(this, "This file is located at: "+uploadUri, Toast.LENGTH_SHORT).show();
if (uri.contains(".txt")) {
Intent uploadIntent = ShareCompat.IntentBuilder.from(this)
.setText("Share Document")
.setType("application/txt")
.setStream(uploadUri)
.getIntent()
.setPackage("com.google.android.apps.docs");
startActivity(uploadIntent);
}else{
//TODO: what to do when it is other file format
}
}
答案 0 :(得分:5)
在onFileClick()中:
更改
String uri = o.getPath();
到
String uri = "file://" + o.getPath();
然后你去!! :)