android - 将 excel 文件上传到 Dropbox 或 Google Drive?

标签 android excel file android-intent android-fileprovider

我目前正在开发一个应用程序,它从 android 中的 sqlite 数据库创建一个 excel 文件(使用 apache poi)。一切正常,除了我无法将文件发送到另一个应用程序。 我实现了一个文件提供程序,因此我的其他应用程序可以获得我的文件的权限:

AndroidManifest.xml:

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.example.ria.masterdetailnoten"
        android:exported="false"
        android:grantUriPermissions="true">

        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"></meta-data>
</provider>

文件路径.xml:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="backup" path="backup/"/>
</paths>

Excel文件.java:

Uri uriFile = FileProvider.getUriForFile(ct, "com.example.ria.masterdetailnoten", backupFile);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setDataAndType(uriFile, "application/vnd.ms-excel");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.createChooser(intent, "Choose");
ct.startActivity(intent);

我确定我的文件正在创建,我可以使用 Apache POI 再次读取它。所以唯一不起作用的是将 Intent 发送到另一个应用程序。


例如,如果我在意向选择器中选择 Google 云端硬盘,则会出现以下错误: “上传失败:请求中没有数据。”

如果我用邮箱应用程序打开它,会出现以下错误: “邮箱无法读取所选文件”

我希望你们能帮助我,感谢你们的帮助!

最佳答案

您是否尝试过使用:putExtra(Intent.EXTRA_STREAM, uriFile) 而不是:setData(AndType)

关于android - 将 excel 文件上传到 Dropbox 或 Google Drive?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27960830/

相关文章:

android - CallScreeningService - 几秒钟后断开调用 - Android 10

c# - 如何使用 C# 在 Excel 自动化中卡住首行并应用筛选器

c++ - 将缓冲区写入文件(存储 1585 字节而不是 1580)

excel - 搜索错误,填充数组并呈现类似数据透视的 View

PHP 取消链接或自行重写自己/当前文件

string - 为什么使用 Golang 设置的文件权限与预期不同?

android - 单击按钮后,从recyclerview中删除项目-Kotlin MVVM Firestore

android - 尝试上传到 AWS s3 时出现 SSL 异常

android - 如何信任 Android 的 Cordova 应用程序中的证书?

python - 如何让 pandas 将 xlsx 文件(包括其工作表)复制到新的 xlsx 文件中