3

I'm currently developing an application which creates an excel file(with apache poi) from the sqlite database in android. Everything is working well, except that I can't send the file to another app. I implemented an fileprovider so I other apps can have permission to my file:

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>

file_paths.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>

ExcelFile.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);

I know for sure that my file is being created and I can read it again with Apache POI. So the only things which doesn't work is sending the intent to another app.


As an example if I choose Google Drive in the intent chooser then following error appears: "Upload failed: request contained no data."

If I open it with the Mailbox App following error appears: "Mailbox could not read the selected file"

I hope you can help me guys, I appreciate your help!

Adrian
  • 807
  • 2
  • 12
  • 25

2 Answers2

3

Have you tried using: putExtra(Intent.EXTRA_STREAM, uriFile) instead of: setData(AndType)?

Felix Gerber
  • 1,615
  • 3
  • 30
  • 40
urps
  • 366
  • 1
  • 4
  • 13
0

I've managed to work this out with intent.selector = Intent(Intent.ACTION_SEND).apply { data = Uri.parse("file:") }

nyarian
  • 4,085
  • 1
  • 19
  • 51