如何上传文件到谷歌Android电子驱动 [英] How do I upload file to google drive from android

查看:221
本文介绍了如何上传文件到谷歌Android电子驱动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花更多的话,一天,但没有得到任何有效的解决方案这为我提供上传/下载文件到谷歌驱动器

I have spend more then one day but not getting any working solution which provide me uploading / downloading files to Google Drive.

我已经试过谷歌播放服务,但我没有找到任何方法,它的上传/下载文件。

I have tried Google Play Service but i didn't find any method which upload / download files.

我试着在谷歌客户库,但也有一些方法都没有解决。

I try Google Client libraries but there are some method are not resolved.

例如:

service.files().insert(body, mediaContent).execute();
errors: The method execute() is undefined for the type Drive.Files.Insert

我可以通过上传图片低于code,但,这是谷歌驱动器文件了装载机。我只能上传一个只有一个文件的时间。

I can upload image through below code but this is Google Drive file up loader. I can only upload one only one file at a time.

mFile = new java.io.File(fileList.get(i));
                Log.i(TAG, "Creating new contents.");
                Drive.DriveApi.newContents(mGoogleApiClient).addResultCallback(
                        new OnNewContentsCallback() {

                            @Override
                            public void onNewContents(ContentsResult result) {

                                if (!result.getStatus().isSuccess()) {
                                    Log.i(TAG, "Failed to create new contents.");
                                    return;
                                }

                                Log.i(TAG, "New contents created.");

                                OutputStream outputStream = result
                                        .getContents().getOutputStream();

                                byte[] byteStream = new byte[(int) mFile
                                        .length()];
                                try {
                                    outputStream.write(byteStream);
                                } catch (IOException e1) {
                                    Log.i(TAG, "Unable to write file contents.");
                                }

                                MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
                                        .setMimeType("image/jpeg")
                                        .setMimeType("text/html")
                                        .setTitle("Android Photo.png").build();
                                // Create an intent for the file chooser, and
                                // start it.
                                IntentSender intentSender = Drive.DriveApi
                                        .newCreateFileActivityBuilder()
                                        .setInitialMetadata(metadataChangeSet)
                                        .setInitialContents(
                                                result.getContents())
                                        .build(mGoogleApiClient);
                                try {
                                    mActivity.startIntentSenderForResult(
                                            intentSender, REQUEST_CODE_CREATOR,
                                            null, 0, 0, 0);
                                    publishProgress(1);
                                } catch (SendIntentException e) {
                                    Log.i(TAG, "Failed to launch file chooser.");
                                    publishProgress(0);
                                }
                            }
                        });

但仍然在争取下载文件。

But still fighting for downloading a file.

推荐答案

大家好我得到的解决方案。我们不应该使用Android的API来完成驱动器访问。我们应该在纯Java code作为谷歌还表示,为广泛获取使用Java库访问驱动器。

Hi guys i get the solution. We should never use Android API for complete Drive access. We should work on pure java code as Google also said that to access Drive for broad access use java libraries.

我删除所有的code与谷歌播放服务。我现在用的完全使用Java和轻松上传,删除,编辑,下载所有我想做的事情。

I remove all the code related to Google play services. I am now using completely using java and easily upload, delete, edit, download all whatever i want.

还有一件事谷歌文档不至Android API提供有关谷歌驱动器的细节描述各自的同时,当Java库工作,你可以得到已经创建的方法等。

One more thing Google doc doesn't provide a detail description about Google Drive in respective to android api while when work on java libraries you can get already created methods and more.

我不会给任何code,但说对我或其他人谁感兴趣的驱动器的完全访问权限使用基于Java的codeS。

I am not giving any code but saying that for me or for others who interested in Drive complete access use Java based codes.

这篇关于如何上传文件到谷歌Android电子驱动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆