我的应用程序可以生成CSV文件并想要分享。我正在使用MIME类型text/comma_separated_values/csv
,但是当我发送Intent
时,选择器没有显示出来,我猜测我的设备不知道如何处理该文件。我应该使用哪种类型呢?
这是我的代码:
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)));
}
我在清单文件中声明:
<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>
我遇到了异常
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()?
我看到这个异常在选择器中没有或仅有一个选项时会出现。
[编辑]
我改变了将数据附加到意图的方式。不再使用sharingIntent.setData(csv),而是使用:
sharingIntent.putExtra(Intent.EXTRA_STREAM, csv);
现在选择器可以正常工作,但是如果我尝试通过电子邮件发送文件,会出现错误:文件无法显示。[/编辑]