【发布时间】: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