我可以阅读从我的私有文件夹的内容? [英] can i read content from my private folder?

查看:100
本文介绍了我可以阅读从我的私有文件夹的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了一个节目中,我做了数据/数据​​/ mypackagename / 目录中的文件。从那里,我尝试将文件附加到电子邮件并发送。

这会发生的问题是在发送邮件作为附件,但在接收邮件时,从未收到的附件出现的文件。

我相信,当解析URI在code中的文件中的一些问题正在发生:

  emailintent.putExtra(Intent.EXTRA_STREAM,Uri.parse(文件://+ outFileName));

我的问题是我是否能访问私有文件夹的数据,我的电话,或者我应该始终把它放在SD卡里面。

如果我把我是SD卡内制作的文件,将附件问题dissappear?


解决方案

  

我的问题是我是否能访问根文件夹的数据,我的电话,或者我应该始终把它放在SD卡里面。


您的应用程序可以在您的应用程序的本地数据存储访问数据 - 通过返回目录getFilesDir()

但是,你没有写的电子邮件程序。电子邮件程序别人写的人,和你开始在其他应用程序的活动。电子邮件程序没有权限来读取文件中的的应用程序的数据存储区。

您要么需要保持对外部存储问题的文件,如其他人所说,或者使用 openFileOutput的版本()这需要 MODE_WORLD_READABLE 作为参数,让你有一个文件,其他应用程序(如电子邮件程序)可以读取。


  

outFileName如下/data/data/com.company.NauticDates/attachment.ics


我当然希望不会。这应该是 /data/data/com.company.NauticDates/files/attachment.ics 。请不要在应用程序中硬线路径。请使用适当的方法来获取目录供你使用,如 getFilesDir() openFileOutput()放文件在应用程序的本地文件存储。

i have made a program in which i make a file in the data/data/mypackagename/ directory. From there i try and attach the file to an email and send it.

The problem that occurs is the file appears while sending the email as an attachment but the attachment is never received when the mail is received.

I believe that some problem is occuring when URI parse the file in the code:

emailintent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+outFileName));

My question is can i access data of the private folder in my phone, or should i always put it inside the sdcard.

If i put the file that i am making inside the sdcard, will the attachment problem dissappear?

解决方案

My question is can i access data of the root folder in my phone, or should i always put it inside the sdcard.

Your application can access data in your application-local data store -- the directory returned by getFilesDir().

However, you did not write the email program. The email program was written by somebody else, and you are starting an activity in that other application. The email program does not have rights to read files in your application's data store.

You will either need to keep the file in question on external storage, as others have suggested, or use the version of openFileOutput() that takes MODE_WORLD_READABLE as a parameter, so you have a file that other applications (such as the email program) can read.

outFileName is as follows /data/data/com.company.NauticDates/attachment.ics

I certainly hope not. That should be /data/data/com.company.NauticDates/files/attachment.ics. Please do not hardwire paths in your application. Please use the appropriate methods to get directories for you to use, such as getFilesDir() or openFileOutput() to put files in the application-local file store.

这篇关于我可以阅读从我的私有文件夹的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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