我如何可以加载邮件附件我的应用程序? [英] How can I load an Email attachment to my app?

查看:133
本文介绍了我如何可以加载邮件附件我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序。

I am developing an Android app.

我已经在的Manifest.xml添加一些设置如下。

I already add some setting in Manifest.xml as follow.

<intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
     <data android:mimeType="application/pdf" />
     <data android:mimeType="text/html" />
     <data android:mimeType="text/htm" />
</intent-filter>

然后,用户可以选择我的应用程序打开附件。

Then, the user can choose my app to open the attachment.

现在的问题是可以在那之后怎么办? 我如何可以访问该文件?

The question is what can I do after that? How can I access the file?

推荐答案

您会收到您声明此过滤器的活动的意图。然后,让你打开文件的URI:

You'll receive an intent in the activity you are declaring this filter. Then, get the URI of the file you're opening:

Intent intent = getIntent();
Uri uri = intent.getData();

这个URI可能会指向一个PDF文件。你可以阅读该文件是这样的:

This URI will probably point to a PDF file. You can read this file like this:

ContentResolver cr = getContentResolver();
InputStream is = cr.openInputStream(uri);

如果您在直接访问文件正在interessed,我建议你写你自己的文件输入流,因为这URI不一定解析到一个真实的文件,如果是的话,你可能没有权限阅读它。下面是关于这种情况下,提供了进一步的解释了一个问题:

If you're interessed in accessing the file directly, I suggest you write your own file from the input stream, since this uri may not necessarily resolve to a real file, and if it does, you may not have permission to read it. Here's a question regarding this case that provides further explanation:

<一个href="http://stackoverflow.com/questions/14364091/retrieve-file-path-from-caught-downloadmanager-intent">Retrieve从抓下载管理意图文件路径

这篇关于我如何可以加载邮件附件我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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