My aplication can generate CSV files that I want to share. I'm using MIME type text/comma_separated_values/csv
, but when I send the Intent
the chooser isn't shown, I guess my device doesn't know how to handle the file. Which type should I use?
This is my code:
Uri csv = lh.createDailyCSV();
if(csv == null){
Toast.makeText(this, getString(R.string.error_creating_csv), Toast.LENGTH_LONG).show();
}
else{
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/comma_separated_values/csv");
sharingIntent.setData(csv);
startActivity(Intent.createChooser(sharingIntent, getResources().getText(R.string.send_to)));
}
I declared in my manifest:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/comma_separated_values/csv" />
</intent-filter>
And I get the exception
03-12 12:19:23.430: E/ActivityThread(24011): Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@412fc920 that was originally registered here. Are you missing a call to unregisterReceiver()?
I've read this Exception occurs when there is none or just 1 option in the chooser.
[EDIT]
I changed how I attach the data to the Intent. Instead of sharingIntent.setData(csv) I used:
sharingIntent.putExtra(Intent.EXTRA_STREAM, csv);
And now the chooser works fine, but if I try to send the file via e-mail I get an error: File couldn't be shown.
[/EDIT]
The correct MIME type would be text/csv
. If that doesn't work, you can use text/plain
which will allow the user to potentially choose from a lot of apps, including Evernote etc.
Update After the update, it seems that you don't want to "share" the file with arbitrary other apps but only send it by e-mail? Please clarify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With