如何读取Android的附加到电子邮件在我的应用程序编程文件? [英] How to read a file attached to an email in my application programatically in android?

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

问题描述

我知道一个办法让这里显示的电子邮件附件的名称:<一href=\"http://stackoverflow.com/questions/6035535/android-get-email-attachment-name-in-my-application\">Android - 在我的应用收到电子邮件附件名称

但无法读取其中附有实际的文件。我如何读附着在应用程序文件编程?

我想这code中的字节数组总是空。我在做什么错了:

 公共静态字符串的getContent(ContentResolver的解析器,乌里URI)
{
  光标光标= resolver.query(URI,新的String [] {} MediaStore.MediaColumns.DATA,NULL,NULL,NULL);
  cursor.moveToFirst();
  INT nameIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
  Log.d(塔,nameIndex +);
  如果(nameIndex&GT; = 0)
  {
    BYTE B [] = cursor.getBlob(nameIndex);
    返回b.length个+;
  }
  其他
  {
    返回null;
  }
}


解决方案

试试这个:

 开放的URI = getIntent()的getData();
InputStream的在= getContentResolver()openInputStream(URI)。
InputStreamReader的读者=新的InputStreamReader(中);

在这一点上,我用手读者一类我在网上叫CSVReader库中找到的,但你可以很直接使用的InputStreamReader。

I know a way to get the Name of attachment in email shown here: Android - get email attachment name in my application.

But could not read actual file which was attached. How do I read that attached file in application programmatically?

I tried this code in which byte array is always null. What am I doing wrong:

public static String getContent(ContentResolver resolver, Uri uri)
{
  Cursor cursor = resolver.query(uri, new String[] { MediaStore.MediaColumns.DATA }, null, null, null);
  cursor.moveToFirst();
  int nameIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
  Log.d("column", nameIndex + "");
  if (nameIndex >= 0)  
  {
    byte b[] = cursor.getBlob(nameIndex);
    return b.length + "";
  } 
  else 
  {
    return null;
  }
}

解决方案

Try this:

Uri uri = getIntent().getData();
InputStream in = getContentResolver().openInputStream(uri);
InputStreamReader reader = new InputStreamReader(in);

At this point, I hand reader to a class I found in a library online called CSVReader, but you could just use the InputStreamReader directly.

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

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