我是Android应用中的Google Drive Integration新手。我需要知道是否可以从我们的自定义Android应用中读取google驱动器的所有内容。
对于例如:我需要打开一个excel文件,该文件存储在google drive&需要获取行数和列数。
我见过以下链接:
但我对以下几行感到困惑:
com.google.android.gms.drive.sample.demo.BaseDemoActivity.EXISTING_FOLDER_ID
com.google.android.gms.drive.sample.demo.BaseDemoActivity.EXISTING_FILE_ID
我在下面看到了链接Android Google Drive EXISTING_FOLDER_ID,EXISTING_FILE_ID
但没有希望
我应该添加什么作为驱动器ID。它始终显示为空。
代码:
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);
}
}
}
请帮助我如何实现它。谢谢
答案 0 :(得分:0)
&#34;对于Eg:我需要打开一个存储在google drive&amp; amp;需要获取行数和列数。&#34;
Google云端硬盘存储&#39;东西&#39;作为blob,因此无法将blob内容解析为行和列。
如果您使用convert = true上传了excel,那么它将创建一个Google Spreadhseet,然后您可以使用电子表格API来获取行和列。