【问题标题】:Attachment is not attaching with email附件未随电子邮件附加
【发布时间】:2014-09-22 14:50:48
【问题描述】:

我正在开发小型 android 应用程序。在那个用户想要备份 SQLite 数据库 所以我尝试 附加 SQLite 数据库到邮件,当我在 android 设备上运行这个应用程序时 ,打开一个对话框并显示 Gmail 和其他一些应用程序。当我选择 Gmail 时,它会自动显示发送 邮件 ID主题电子邮件内容附件 还有,现在我点击发送邮件被发送到相应的邮箱。当我检查电子邮件附件不可用时,他们的??为什么没有附加 SQLite 数据库?我的代码有什么问题?

File getdbdatapath= Environment.getDataDirectory();
String currentDBPath = "/data/com.example.appname/databases/dbname/"; 
File path=new File(getdbdatapath, currentDBPath);
Log.d("Path", path.toString());

//File extdb= Environment.getExternalStorageDirectory();
//String extpath=extdb+"/NewFolder/dbname";
//File pathp=new File(extdb, extpath);
//Log.d("New Path", pathp.toString());

Log.i(getClass().getSimpleName(), "send  task - start");

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

String address = "clientmailid@gmail.com";
String subject = "Application Database";
String emailtext = "Please check the database as attachement";

//emailIntent.setType("Application/database");
//emailIntent.setType("text/html");
//emailIntent.setType("message/rfc822");            
emailIntent.setType("vnd.android.cursor.dir/email");  

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { address });

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);

emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + path));

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext);

startActivity(Intent.createChooser(emailIntent, "Send Mail..."));

我提到了这个link1link2link3,将mailIntent.setType("text/html"); 更改为许多setTypes。也从外部获取数据库,但没有用。帮我。提前致谢。


这段代码运行良好

String extpath=Environment.getExternalStorageDirectory() +"/NewFolder/dbname";
File pathp=new File(extpath);

在我上面的代码中,它需要 mnt>sdcard>mnt>sdcard>NewFloder>dbname 所以现在无法附加此代码工作正常。

【问题讨论】:

  • 将文件保存在数据文件夹中将永远无法工作,因为其他应用程序永远无法访问该文件夹路径。您需要通过在 sdcard 上创建一个文件夹并将文件放置/复制/移动到该文件夹​​来保留要附加到 sdcard 上的文件。
  • @RajenRaiyarela 嗨,我也尝试了该方法,请查看我的代码上方,我评论了该行。 File extdb= Environment.getExternalStorageDirectory();

标签: android android-sqlite email-attachments


【解决方案1】:

您需要将文件复制到电子邮件活动可以访问的位置。例如。到 SD 卡。

【讨论】:

  • 是的,我试过这个方法,也检查我上面的代码,我现在评论它。 File extdb= Environment.getExternalStorageDirectory();
  • 当我从对话框中选择 Gmail 时,它会在两种情况下显示准确的数据库名称,然后我将邮件发送到 abc@gamil.com。现在,如果我在 abc@gmail.com 中检查邮件,收到的邮件没有附件。
  • 伤心,我在安卓设备上运行应用程序,我复制了 APK 文件并安装在我的安卓设备上。在模拟器中创建gmail帐户的问题。我现在能做什么 ?这里有什么问题?
  • 你也可以从安卓设备获取日志
  • 非常感谢您宝贵的回答和时间。现在只需对代码进行少量更改即可正常工作。
猜你喜欢
  • 2019-03-14
  • 1970-01-01
  • 2015-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-30
  • 1970-01-01
相关资源
最近更新 更多