【发布时间】:2018-01-30 00:51:28
【问题描述】:
我在将音频列表上传到谷歌驱动器时遇到问题。
我可以从目录上传单个音频文件,但我尝试上传音频文件列表失败。
这是单个音频文件的路径
final String path = new String(Environment.getExternalStorageDirectory() + "/CallLogs/Yaendi Yaendi.mp3");
如何上传CallLogs目录下的所有音频文件。
public void CreateFileOnGoogleDrive(DriveApi.DriveContentsResult result) {
final DriveContents driveContents = result.getDriveContents();
// Perform I/O off the UI thread.
new Thread() {
@Override
public void run() {
// write content to DriveContents
OutputStream outputStream = driveContents.getOutputStream();
final String path = new String(Environment.getExternalStorageDirectory() + "/CallLogs/Yaendi Yaendi.mp3");
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(new File(path));
} catch (FileNotFoundException e) {
showErrorDialog();
e.printStackTrace();
}
byte[] buf = new byte[1024];
int bytesRead;
try {
if (inputStream != null) {
while ((bytesRead = inputStream.read(buf)) > 0) {
outputStream.write(buf, 0, bytesRead);
}
}
} catch (IOException e) {
showErrorDialog();
e.printStackTrace();
}
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("callLog")
.setMimeType("audio/mpeg")
.setStarred(true).build();
// create a file in root folder
Drive.DriveApi.getRootFolder(mGoogleApiClient)
.createFile(mGoogleApiClient, changeSet, driveContents).setResultCallback(fileCallback);
}
}.start();
Toast.makeText(getActivity(), "Created Successfully", Toast.LENGTH_SHORT).show();
}
以上代码用于将单个音频文件上传到谷歌驱动器。 请帮助我如何将所有文件上传到谷歌驱动器。
【问题讨论】:
-
您可能需要查看 SO post 和 Upload multiple files to Google Drive 讨论设置一个变量以列出您必须上传的所有文件,然后在有要上传的文件时创建一个循环.您还可以尝试创建/上传文件的批处理请求(通过 asynctask),如post 中所述。希望这会有所帮助。