gpt4 book ai didi

android - 在不使用元数据、Android Google Drive Api 的情况下了解 Google 文档类型(工作表、幻灯片或文档)

转载 作者:行者123 更新时间:2023-11-29 01:16:26 25 4
gpt4 key购买 nike

我正在尝试创建一个打开 Drive 文件夹并让用户选择文件(工作表、文档或幻灯片)并使用 Google Drive API 打开它的应用程序,但我不知道如何识别文件的类型,我尝试使用元数据作为 API 的官方演示建议,但我无法使其工作。

我尝试了下面的代码,但没有成功:

DriveId driveId = (DriveId) data.getParcelableExtra(
OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);

Intent mainIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://docs.google.com/document/d/" + driveId.getResourceId()));

try {
startActivity(mainIntent);
}catch (Exception e) {

mainIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://docs.google.com/spreadsheet/d/" + driveId.getResourceId()));

try{
startActivity(mainIntent);
}catch(Exception e1){

mainIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://docs.google.com/slide/d/" + driveId.getResourceId()));

}
}
}
finish();

如果我尝试打开一个文档,它可以正常工作,但如果我尝试打开一个电子表格,它会失败,因为 Intent 已正确启动,但未找到该文档。

是否有任何其他方法可以知道文档类型以便使用正确的 url 打开?哦,我应该如何正确使用元数据来打开它?

谢谢。

最佳答案

可以通过调用从DriveId获取DriveFile来获取文件类型,可以查看File Metadata有关更多详细信息,请参阅文档部分。

OpenFileActivityBuilder 将失败,因为您正在调用 startActivity(如 Google API 中所示)

Note: you cannot use #startActivity to invoke the activity. This will fail.

使用构建器中的 IntentSender 通过调用 startIntentSenderForResult(以及其他所需的回调)来启动 Activity

关于android - 在不使用元数据、Android Google Drive Api 的情况下了解 Google 文档类型(工作表、幻灯片或文档),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39258204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com