发送SQLite数据库作为电子邮件附件中的Andr​​oid [英] Sending Sqlite database as email attachment in Android

查看:185
本文介绍了发送SQLite数据库作为电子邮件附件中的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序,我是用秒杀发送附件。

I have a simple app which I am using to spike sending attachments.

我已成功地发送从SD卡的文本文件(虽然我不能让这与在应用程序使用私有面积 openFileOutput(文件名,0)),但我现在想送一个数据库。

I have managed to send a text file from the SD card (although I couldn't get this to work with a file created in the apps private area using openFileOutput(fileName, 0)) but I now want to send a database.

通过调试,我可以验证数据库存在,并且在其只有一个表项。我的code派看起来是这样的:

By debugging I can verify the database exists and has an entry in its only table. My code to send looks like this:

gmailButton = (Button) findViewById(R.id.button);
gmailButton.setOnClickListener(new OnClickListener()
{
    @Override
    public void onClick(View v)
    {
        Intent sendIntent = new Intent(Intent.ACTION_SEND); 
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, "subject line"); 
        sendIntent.putExtra(Intent.EXTRA_TEXT,"Body of email"); 
        Uri uri = Uri.fromFile(getDatabasePath("TEST_DB"));
        //uri = file:///data/data/com.gmailspike/databases/TEST_DB
        sendIntent.putExtra(Intent.EXTRA_STREAM, uri); 
        sendIntent.setType("application/octet-stream");

        startActivity(Intent.createChooser(sendIntent,"Email:"));
    }
})

然而,当电子邮件客户端打开附件有大小为0字节,如果我触摸打开附件的客户说该文件无法找到。

However, when the email client opens the attachment has a size of 0 bytes and if I touch to open the attachment the client says the file cannot be found.

任何想法?我不知道MIME类型是否正确,或者即使是很重要的!

Any ideas? I'm not sure the mime type is correct, or even if it is important!

推荐答案

我记得有过这样的问题也试图用图像附件发送的电子邮件时,链接到存储在应用的私密数据文件夹中的文件。附件就是缺少。

I remember having had an issue like this too, when trying to send an email with an image attachment, linking to a file stored in the apps private data folder. The attachment is just missing.

使用邮件意图打开新的应用程序来处理邮件的创作。因此,你要么需要编写一个内容提供商允许其他应用程序访问您的私人数据。

Using the mail intent opens a new application to handle the mail-creation. Therefore you either need to write a Content Provider to allow other applications access to your private data.

还是第一次内容复制到公共场所,并从那里添加到邮件的意图(这种方法只有一个SD卡是present与大多数手机)。该<一href="http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory%28%29"相对=nofollow>外部Storage.getExternalStorageDirectory()也许可以用在这种情况下。

Or copy the content to public area first and add it to the mail intent from there (this only works when a SD-Card is present with most phones). The External Storage.getExternalStorageDirectory() could maybe used in that case.

希望这有助于寻找解决办法。

Hope this helps to find a solution.

这篇关于发送SQLite数据库作为电子邮件附件中的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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