Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将数据上载到特定的google drive帐户_Android_Google Drive Api_Google Drive Android Api - Fatal编程技术网

Android 将数据上载到特定的google drive帐户

Android 将数据上载到特定的google drive帐户,android,google-drive-api,google-drive-android-api,Android,Google Drive Api,Google Drive Android Api,我正试图上传数据(图像或视频)到特定的谷歌驱动器。 我希望我的应用程序的用户登录到他们的google帐户,然后从文档中选择特定文件,然后将文件上载到特定的google驱动器(不在用户google驱动器上) 到目前为止我做了什么? 到目前为止,我的应用程序运行良好。用户使用google帐户登录并选择文件。但是这个文件会转到他们的谷歌硬盘。 我用谷歌硬盘api搜索了上传数据到其他谷歌硬盘,但没有找到任何有用的东西 我想要实现什么? 我想当用户上传数据(视频)到特定的谷歌驱动器。我有谷歌硬盘的App_

我正试图上传数据(图像或视频)到特定的谷歌驱动器。 我希望我的应用程序的用户登录到他们的google帐户,然后从文档中选择特定文件,然后将文件上载到特定的google驱动器(不在用户google驱动器上)

到目前为止我做了什么?

到目前为止,我的应用程序运行良好。用户使用google帐户登录并选择文件。但是这个文件会转到他们的谷歌硬盘。 我用谷歌硬盘api搜索了上传数据到其他谷歌硬盘,但没有找到任何有用的东西

我想要实现什么?

我想当用户上传数据(视频)到特定的谷歌驱动器。我有谷歌硬盘的App_键,我想上传数据

附上我的登录和上传数据代码

多谢各位

登录代码

GoogleSignInClient googleSignInClient = buildGoogleSignInClient();
startActivityForResult(googleSignInClient.getSignInIntent(), REQUEST_CODE);

private GoogleSignInClient buildGoogleSignInClient() {
    GoogleSignInOptions signInOptions = new GoogleSignInOptions
              .Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
              .requestScopes(Drive.SCOPE_FILE)
              .build();
          return GoogleSignIn.getClient(this, signInOptions);
    }
使用以下命令上载文件:

    final Task<DriveFolder> rootFolderTask = mDriveResourceClient.getRootFolder();
    final Task<DriveContents> createContentsTask = mDriveResourceClient.createContents();
    Tasks.whenAll(rootFolderTask, createContentsTask)
            .continueWithTask(new Continuation<Void, Task<DriveFile>>() {
                @Override
                public Task<DriveFile> then(@NonNull Task<Void> task) throws Exception {
                    DriveFolder parent = rootFolderTask.getResult();
                    DriveContents contents = createContentsTask.getResult();
                    File file = new File(uri.toString());
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    byte[] buf = new byte[1024];
                    FileInputStream fis = new FileInputStream(file);
                    for (int readNum; (readNum = fis.read(buf)) != -1;) {
                        baos.write(buf, 0, readNum);
                    }
                    OutputStream outputStream = contents.getOutputStream();
                    outputStream.write(baos.toByteArray());

                    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                            .setTitle("MyVideo.mp4") // Provide you video name here
                            .setMimeType("video/mp4") // Provide you video type here
                            .build();

                    return mDriveResourceClient.createFile(parent, changeSet, contents);
                }
            })
            .addOnSuccessListener(this,
                    new OnSuccessListener<DriveFile>() {
                        @Override
                        public void onSuccess(DriveFile driveFile) {
                            Toast.makeText(MainActivity.this, "Upload Started", Toast.LENGTH_SHORT).show();
                        }
                    })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.e(TAG, "Unable to create file", e);
                    Toast.makeText(MainActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
final Task rootFolderTask=mDriveResourceClient.getRootFolder();
最终任务createContentsTask=mDriveResourceClient.createContents();
Tasks.whenAll(rootFolderTask、createContentsTask)
.continueWithTask(新的continueWithTask(){
@凌驾
公共任务(@NonNull Task Task)引发异常{
DriveFolder parent=rootFolderTask.getResult();
DriveContents=createContentsTask.getResult();
File File=新文件(uri.toString());
ByteArrayOutputStream bas=新的ByteArrayOutputStream();
字节[]buf=新字节[1024];
FileInputStream fis=新的FileInputStream(文件);
对于(int readNum;(readNum=fis.read(buf))!=-1;){
写入(buf,0,readNum);
}
OutputStream OutputStream=contents.getOutputStream();
write(baos.toByteArray());
MetadataChangeSet changeSet=新建MetadataChangeSet.Builder()
.setTitle(“MyVideo.mp4”)//在此处提供视频名称
.setMimeType(“video/mp4”)//在此处提供视频类型
.build();
返回mDriveResourceClient.createFile(父级、变更集、内容);
}
})
.addOnSuccessListener(此,
新OnSuccessListener(){
@凌驾
成功时公共无效(驱动文件驱动文件){
Toast.makeText(MainActivity.this,“上载已开始”,Toast.LENGTH_SHORT.show();
}
})
.addOnFailureListener(此,新的OnFailureListener(){
@凌驾
public void onFailure(@NonNull异常e){
Log.e(标记“无法创建文件”,e);
Toast.makeText(MainActivity.this,“+e.getMessage(),Toast.LENGTH_SHORT.show();
}
});

如果您想将其发送到另一个google drive帐户,我认为您可以使用

Team Drive是一个共享空间,团队可以在其中轻松地从任何设备存储、搜索和访问其文件。 然后,您可以添加当前作为团队一部分登录的用户。然后他们可以共享并上传到特定的团队驱动


我希望有帮助

不,我不要这个。在团队驱动中,Google驱动帐户持有人必须首先在团队中添加成员。我想要的是:将Google Drive帐户持有人的帐户添加到我的应用程序中,任何使用其帐户登录的人都可以将数据上传到该帐户,这可以称为共享文件夹。因此,每个人都可以访问该文件夹,并且每个人都可以直接将数据上载到该文件夹。未经账户持有人许可。