如何安装本地存储在应用程序目录下的文本文件文本文件、应用程序、目录下

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

我有一个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.

阅读全文

相关推荐

最新文章