Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.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应用程序获取谷歌硬盘数据_Android_Google Drive Api - Fatal编程技术网

从Android应用程序获取谷歌硬盘数据

从Android应用程序获取谷歌硬盘数据,android,google-drive-api,Android,Google Drive Api,我是Android应用程序中Google Drive集成的新手。我需要知道是否可以从我们的定制Android应用程序中读取Google Drive的所有内容 例如:我需要打开一个存储在谷歌硬盘中的excel文件&需要获取行数和列数 我看到了以下链接: 但我对以下几行感到困惑: com.google.android.gms.drive.sample.demo.BaseDemoActivity.EXISTING_FOLDER_ID com.google.android.gms.drive.samp

我是Android应用程序中Google Drive集成的新手。我需要知道是否可以从我们的定制Android应用程序中读取Google Drive的所有内容


例如:我需要打开一个存储在谷歌硬盘中的excel文件&需要获取行数和列数

我看到了以下链接:

但我对以下几行感到困惑:

com.google.android.gms.drive.sample.demo.BaseDemoActivity.EXISTING_FOLDER_ID
com.google.android.gms.drive.sample.demo.BaseDemoActivity.EXISTING_FILE_ID
我看到了下面的链接

但是没有希望

我应该添加什么作为驱动器ID。它总是显示null

代码:

RetrieveContentsActivity:

public class RetrieveContentsActivity extends BaseDemoActivity {

    private static final String TAG = "RetrieveContentsActivity";

    @Override
    public void onConnected(Bundle connectionHint) {
        super.onConnected(connectionHint);
        Drive.DriveApi.fetchDriveId(getGoogleApiClient(), EXISTING_FILE_ID)
                .setResultCallback(idCallback);
    }

    final private ResultCallback<DriveIdResult> idCallback = new ResultCallback<DriveIdResult>() {
        @Override
        public void onResult(DriveIdResult result) {
            new RetrieveDriveFileContentsAsyncTask(
                    RetrieveContentsActivity.this).execute(result.getDriveId());
        }
    };

    final private class RetrieveDriveFileContentsAsyncTask
            extends ApiClientAsyncTask<DriveId, Boolean, String> {

        public RetrieveDriveFileContentsAsyncTask(Context context) {
            super(context);
        }

        @Override
        protected String doInBackgroundConnected(DriveId... params) {
            String contents = null;
            DriveFile file = Drive.DriveApi.getFile(getGoogleApiClient(), params[0]);
            DriveContentsResult driveContentsResult =
                    file.open(getGoogleApiClient(), DriveFile.MODE_READ_ONLY, null).await();
            if (!driveContentsResult.getStatus().isSuccess()) {
                return null;
            }
            DriveContents driveContents = driveContentsResult.getDriveContents();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(driveContents.getInputStream()));
            StringBuilder builder = new StringBuilder();
            String line;
            try {
                while ((line = reader.readLine()) != null) {
                    builder.append(line);
                }
                contents = builder.toString();
            } catch (IOException e) {
                Log.e(TAG, "IOException while reading from the stream", e);
            }

            driveContents.discard(getGoogleApiClient());
            return contents;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            if (result == null) {
                showMessage("Error while reading from the file");
                return;
            }
            showMessage("File contents: " + result);
        }
    }
}

请帮助我了解我应该如何实现它。谢谢你,例如:我需要打开一个存储在google drive中的excel文件,需要获取行数和列数

GoogleDrive将“东西”存储为blob,因此无法将blob内容解析为行和列


如果上载excel时convert=true,它将创建一个Google Spreadhseet,然后您可以使用电子表格API获取行和列。

谢谢,可以获取任何图像或任何其他文本文件吗?你能告诉我如何从谷歌硬盘获取所有文件,并将其列在我的应用程序中……你可以获取任何类型的文件。要列出它们,请使用files.list API调用。再见,谢谢,但您能告诉我如何在这里获取驱动器ID RetrieveContentsActivity.this.ExecuteSult.getDriveId;在我的项目中显示null,DriveFile file=Drive.DriveApi.getFilegetGoogleApiClient,params[0];显示显示未解析引用时出错:getFile,应执行什么操作?请安静!