android-studio - 对于 ACTION_VIEW,Google 表格需要哪些信息?

标签 android-studio google-sheets

我的应用程序创建了一个可以通过 Google Sheets 和 MS-Excel 打开的 Excel 文件。但是当我通过我的应用程序使用 ACTION_VIEW 打开它时,Google 表格无法查看 Excel 文件,但它在 MS-Excel 中运行良好。通过 Google Sheet 查看文件时,它显示一条消息“Google Sheets 无法打开您的电子表格”。

我尝试清除 Excel 文件中的所有数据,只查看空文件,但 Google 表格仍然存在此问题。

Uri data = FileProvider.getUriForFile(dbActivity.getApplicationContext(),"com.aaa.fileprovider", createdFile);
dbActivity.getApplicationContext().grantUriPermission(dbActivity.getPackageName(), data, FLAG_GRANT_READ_URI_PERMISSION);
dbActivity.getApplicationContext().grantUriPermission(dbActivity.getPackageName(), data, FLAG_GRANT_WRITE_URI_PERMISSION);
Intent openIntent = new Intent();
openIntent.setType(applicationType);
openIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_GRANT_READ_URI_PERMISSION);
openIntent.setAction(Intent.ACTION_VIEW);
openIntent.setData(data);
openIntent.putExtra(Intent.EXTRA_STREAM, data);
try {
    dbActivity.startActivity(openIntent);
}
catch (Exception ex){
    Toast toast = Toast.makeText(dbActivity, "No applications to open the file.", Toast.LENGTH_LONG);
    toast.show();
}

大多数人的手机上没有 MS-Excel,所以我希望我的应用程序能够查看 Google Sheets 创建的文件

最佳答案

Google 表格似乎要求您在 ACTION_VIEW 意图上设置数据和 MIME 类型。
替换这个:

openIntent.setData(data);
有了这个:
openIntent.setDataAndType(data, mimeType)
哪里mimeType是您发送的文件的 MIME 类型 - 例如,“text/csv”。

关于android-studio - 对于 ACTION_VIEW,Google 表格需要哪些信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58048163/

相关文章:

google-sheets - 忽略给定单词的大小写

google-sheets - 如何过滤 View 两列 OR 而不是 AND?

javascript - 如何从 Google 表格导入数据?

excel - 无损失地汇总重复数据

android - 在Studio下的错误目录中创建文件

添加 ScrollView 时的 Android Studio 渲染

java - Android Studio中的Card View添加点击效果波纹效果

ios - 使用 Flutter 插入 sqflite 时出现问题

android - 为什么AndroidStudio3.0启用的高级分析要求API级别低于26

javascript - 如何通过javaScript和Ajax发送 'put'请求?