问题描述
我要检索Gmail应用程序内容的文件路径。
我得到的内容URI类似于:
I have to retrieve the file path of the content from gmail app.I get content uri similar to:
content://gmail-ls/messages/mymailid%40gmail.com/4/attachments/0.1/BEST/false
我试着查询了内容,但我只得到两列的标题和大小。我想获得的文件路径。
I tried queried for the contents but I get only two columns the title and the size. I want to get the file path.
请对此有所帮助。
推荐答案
我觉得你不能直接检索文件的路径,作为附件存储在谷歌服务器上。你可以,但是,通过访问和ContentResolver的InputStream中的文件数据,并复制附件的数据存储。
I think you cannot retrieve the file path directly, as the attachment is stored on Google servers. You can, however, access the file data using ContentResolver and InputStream, and copy the attachment's data to your storage.
href=\"http://carving$c$c.blogspot.com/2009/08/how-to-open-gmail-attachments-with.html\">雕刻code博客,我用这个片断:
Inspired by CarvingCode blog, I use this snippet:
if (intent.getScheme().compareTo("content")==0)
{
try
{
InputStream attachment = getContentResolver().openInputStream(data);
if (attachment == null)
Log.e("onCreate", "cannot access mail attachment");
else
{
FileOutputStream tmp = new FileOutputStream("/mnt/sdcard/attachment.pdf");
byte []buffer = new byte[1024];
while (attachment.read(buffer) > 0)
tmp.write(buffer);
tmp.close();
attachment.close();
}
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这篇关于如何从Gmail的内容提供商的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!