如何安装本地存储在应用程序目录下的文本文件 [英] How to attach a text file stored locally in app directory

查看:101
本文介绍了如何安装本地存储在应用程序目录下的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序直接保存为文本文件到手机,在应用程序的安装目录。我需要允许用户创建一个新的电子邮件,附上该保存的文本文件。当我开始发送电子邮件的意图,一切都显示在Gmail中正确的,但附件不会发送。我所有的堆栈溢出的搜索似乎只处理从SD卡将一个图像文件。下面是code,我用。请让我知道,如果我做了一些不正确的。

I have an Android app that saves a text file directly onto the phone, in the app's install directory. I need to allow the user to create a new email, attaching this saved text file. When I start the intent to send the email, everything shows up in Gmail correctly, but the attachment does not get sent. All of my searches on stack overflow seem to only deal with attaching an image file from the SD card. Below is the code that I used. Please let me know if I have done something incorrectly.

File myFile = new File(getFilesDir() + "/" + "someFile.txt");
FileOutputStream stream = null;

if( file != null )
{
    steam = openFileOutput("someFile.txt", Context.MODE_WORLD_READABLE);
    stream.write(some_data);

    Uri uri = Uri.fromFile(myFile);

    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    sendIntent.putExtra(Intent.EXTRA_TEXT, email_text);
    sendIntent.putExtra(Intent.EXTRA_STREAM, uri);

    file.close();

    startActivity(Intent.createChooser(sendIntent, "Email:"));
}

我也试着sendIntent.setType(应用程序/八位字节流);但这并没有发挥作用。我在为什么该文件不重视和被发送的损失。

I've also tried sendIntent.setType("application/octet-stream"); but that didn't make a difference. I'm at a loss for why the file doesn't attach and get sent.

任何想法?

推荐答案

我已经看到了这一点之前,我可以解决的唯一途径是通过写文件到SD卡。

I've seen this before and the only way I could solve it was by writing the file to the SD card.

有值得尝试写入该文件的SD卡和连接它如果只消除文件位置作为问题的原因。

It's worth trying writing to the file to the SD card and attaching it if only to eliminate the files location as the cause of the problem.

这篇关于如何安装本地存储在应用程序目录下的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆