Please go back and re-read my previous message, starting with HOWEVER.
I answered this question there.

You CANNOT attach files from your app's internal directory. The mail
app has no access to that file, it is private to your application.
This is the intended behavior. If you want to provide that content to
the mail application, you will have to do so via a content provider.

On Jun 8, 8:51 pm, adag <[email protected]> wrote:
> Hello Bob,
>
> Thanks for your suggestion. I have two questions to you..
> How do I attach with EXTRA_STREAM in that case while I put the file
> with Uri.fromFile().
>         File dirFile = getFilesDir();
>         File zibraFile = new File(dirFile,"zibra.csv");
>         Uri zibraUri = Uri.fromFile(zibraFile);
>         sendIntent.putExtra(Intent.EXTRA_STREAM, zibraUri);
>        But the email does not carry any attachement. Any solution
> please
>
> Please provide any solution as I am unable to attach the file from
> internal directory.
>
> ag
> On Jun 9, 3:23 am, Bob Kerns <[email protected]> wrote:
>
>
>
> > 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