Android的 - 让我的应用程序的电子邮件附件名称 [英] Android - get email attachment name in my application

查看:82
本文介绍了Android的 - 让我的应用程序的电子邮件附件名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图加载一个电子邮件附件在我的应用程序。我能得到的内容,但我不能获取文件名。

I'm trying to load an email attachment in my application. I can get the content, but I cannot get the file name.

下面是我的意图过滤器是这样的:

Here's how my intent filter looks like:

        <intent-filter>
            <action
                android:name="android.intent.action.VIEW" />
            <category
                android:name="android.intent.category.DEFAULT" />
            <data
                android:mimeType="image/jpeg" />
        </intent-filter>

下面是我所得到的:

信息/ ActivityManager(97):首发:   意图 {   ACT = android.intent.action.VIEW   DAT =内容://gmail-ls/messages/john.doe%40gmail.com/42/attachments/0.1/SIMPLE/false   (典型值)=为image / jpeg FLG = 0x3880001   CMP = com.myapp / .ui.email.EmailDocumentActivityJpeg   }从PID 97

INFO/ActivityManager(97): Starting: Intent { act=android.intent.action.VIEW dat=content://gmail-ls/messages/john.doe%40gmail.com/42/attachments/0.1/SIMPLE/false typ=image/jpeg flg=0x3880001 cmp=com.myapp/.ui.email.EmailDocumentActivityJpeg } from pid 97

在我的活动我得到的URI,并用它来获得文件内容的输入流:

In my activity I get the Uri and use it to get the input stream for the file content:

InputStream is = context.getContentResolver().openInputStream(uri);

我在哪里可以找到在此情况下,文件名?

Where can I find the file name in this scenario?

推荐答案

我有同样的问题今天解决,并最终找到在另一篇文章中解决办法:<一href="http://stackoverflow.com/questions/6031410/android-get-attached-filename-from-gmail-app">Android从Gmail应用程序获得附加的文件名 的主要思想是,该URI你得到可以既用于检索文件的内容和用于查询,以获得更多的信息使用。 我做了一个快速的效用函数来检索名称:

I had the same problem to solve today and ended up finding the solution in another post : Android get attached filename from gmail app The main idea is that the URI you get can be used both for retrieving the file content and for querying to get more info. I made a quick utility function to retrieve the name :

public static String getContentName(ContentResolver resolver, Uri uri){
    Cursor cursor = resolver.query(uri, null, null, null, null);
    cursor.moveToFirst();
    int nameIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
    if (nameIndex >= 0) {
        return cursor.getString(nameIndex);
    } else {
        return null;
    }
}

您可以使用这种方式在你的活动:

You can use it this way in your activity :

Uri uri = getIntent().getData();
String name = getContentName(getContentResolver(), uri);

这是为我工作(检索的PDF文件的名称)。

That worked for me (retrieving the name of PDF files).

这篇关于Android的 - 让我的应用程序的电子邮件附件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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