i have made a program in which i make a file in the d开发者_运维百科ata/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.
You can put the file in assets folder. and you can read file using the following code
InputStream myInput = context.getAssets().open("filename");
Thanks Deepak
精彩评论