Android从gmail应用程序获取附加文件名 [英] Android get attached filename from gmail app

查看:19
本文介绍了Android从gmail应用程序获取附加文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从 gmail 应用程序中检索内容的文件名.

I have to retrieve the filename of the content from gmail app.

我得到的内容 uri 类似于

i get content uri some thing similar to

content://gmail-ls/messages/mymailid%40gmail.com/4/attachments/0.1/BEST/false

content://gmail-ls/messages/mymailid%40gmail.com/4/attachments/0.1/BEST/false

我看到一些应用程序从中获取文件名,例如 这个应用程序

i see some apps getting the file names from it like this app

请对此提供帮助.

提前致谢.

推荐答案

基本上,你需要获取文件系统,并获取存储信息的游标:

Basically, you need to acquire the file system and get a cursor where the info is stored:

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.Toast;

public class CheckIt extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent theIntent = getIntent();
        String attachmentFileName = "No file name found";
        if (theIntent != null && theIntent.getData() != null) {
            Cursor c = getContentResolver().query(
                theIntent.getData(), null, null, null, null);
            c.moveToFirst();
            final int fileNameColumnId = c.getColumnIndex(
                MediaStore.MediaColumns.DISPLAY_NAME);
            if (fileNameColumnId >= 0)
                attachmentFileName = c.getString(fileNameColumnId);
        }
        Toast.makeText(this, attachmentFileName, Toast.LENGTH_LONG).show();
    }

}

在返回的光标中还有另一列 - MediaStore.MediaColumns.SIZE.至少这是我在我的 Desire HD 上使用 GMail 所得到的.只需通过在 GMail 中操作邮件并点击预览按钮来尝试上述代码.

In the cursor returned there is another column - MediaStore.MediaColumns.SIZE. At least that's what I get with GMail on my Desire HD. Just try the above code by operning a mail in GMail and hitting the preview button.

当然,不要忘记将以下内容添加到 Manifest.xml 中的活动部分(不要从活动中删除 android.intent.category.LAUNCHER 意图过滤器部分,否则将无法通过启动器查看):

Of course, do not forget to add the following to the activity section in the Manifest.xml (do not drop the android.intent.category.LAUNCHER intent-filter section from the activity otherwise it will not be viewable through the launcher):

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

这篇关于Android从gmail应用程序获取附加文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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