Please do not construct filenames and Uri's by pasting together
strings.

The correct way to write this is:

                    Uri.fromFile(new
File(Environment.getExternalStorageDirectory(), "zibra.txt"))

or to make it a bit more clear:
File dirFile = Environment.getExternalStorageDirectory();
File zibraFile = new File(dir, "zibra.txt");
Uri zibraUri = Uri.fromFile(zibraFile);

Or, if you need a URI instead of a Uri:
URI zibraURI = zibraFile.toURI();

There's also File.toURL().

HOWEVER, the documentation for Intent.EXTRA_STREAM says you need a
content: URI (I presume that should be Uri?), not a file: one. If you
want to give the other application access to your app's data, create a
content provider. Applications don't have access to files belonging to
other applications. A content provider (and content: URI) give your
application control over what information to make available, and to
whom.

On Jun 7, 10:33 pm, adag <[email protected]> wrote:
> Hello,
>
> I am successful in creating file using openFileOutput(). and can read
> the file using openFileInput().
> I am able attach file from external storage sdcard while emailing the
> same using getExternalStorageDirectory as
> sendIntent.putExtra(Intent.EXTRA_STREAM,
> Uri.parse("file://"+Environment.getExternalStorageDirectory()+"/
> zibra.txt"));
>
> But while trying to attach file from the openOutputFile stored area
> using sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+
> getFilesDir() + "/zibra.txt"));, resulting emptied file emailing.
> My file is stored in "/data/data/com.example/files/zibra.txt".
>
> Could you please point out what is going wrong in it?
> Intent sendIntent = new Intent(Intent.ACTION_SEND);
>         sendIntent.putExtra(Intent.EXTRA_EMAIL, recipients);
>         sendIntent.putExtra(Intent.EXTRA_SUBJECT, "attachment test");
>         sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse
>                         ("file://"+ getFilesDir() + "/zibra.txt"));
>                         
> //("file://"+Environment.getExternalStorageDirectory()+"/
> zibra.txt"));
>         sendIntent.setType("text/plain");
>         startActivity(Intent.createChooser(sendIntent, "Send mail..."));

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to