如何发送图像而不存储在 SD 卡中?

发布于 2024-09-24 04:46:10 字数 125 浏览 3 评论 0原文

我正在开发一个显示图像的应用程序。该应用程序提供了将图像作为附件通过电子邮件发送的选项。我必须将图像保存到 SD 卡才能将图像作为附件通过电子邮件发送。

是否可以将图像作为附件通过电子邮件发送,而不先将其写入 SD 卡?

I am developing an application that displays images. The application provides an option to email the image as an attachment. I have to save the image to the SD card in order to email the image as an attachment.

Is it possible to email the image as an attachment without writing it to the SD card first?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千笙结 2024-10-01 04:46:10

@西瓦拉杰
例如,如果您将图像存储在手机中的任何位置(甚至在私人文件夹中)
如果您根本不想将其存储在 openFile 方法中,只需修改它即可。
使用正确的权限属性在清单中注册您的提供者,就是这样!

public class ImageProvider extends ContentProvider {
        private static final String URI_PREFIX = "content://com.android.myproject.anythingyouwant";

        public static String constructUri(String url) {
            Uri uri = Uri.parse(url);
            return uri.isAbsolute() ? url : URI_PREFIX + url;
        }

        @Override
        public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
            File file = new File(uri.getPath());
            ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
            return parcel;
        }

        @Override
        public boolean onCreate() {
            return true;
        }

        @Override
        public int delete(Uri uri, String s, String[] as) {
            throw new UnsupportedOperationException("Not supported by this provider");
        }

        @Override
        public String getType(Uri uri) {
            throw new UnsupportedOperationException("Not supported by this provider");
        }

        @Override
        public Uri insert(Uri uri, ContentValues contentvalues) {
            throw new UnsupportedOperationException("Not supported by this provider");
        }

        @Override
        public Cursor query(Uri uri, String[] as, String s, String[] as1, String s1) {
            throw new UnsupportedOperationException("Not supported by this provider");
        }

        @Override
        public int update(Uri uri, ContentValues contentvalues, String s, String[] as) {
           throw new UnsupportedOperationException("Not supported by this provider");
        }
    }

@sivaraj
For example, if you store you image anywhere in the phone (even in a private folder)
Just modify it if you don't want to store it at all in the openFile method.
Register your provider in your manifest with the right authorities attribute and that's it !

public class ImageProvider extends ContentProvider {
        private static final String URI_PREFIX = "content://com.android.myproject.anythingyouwant";

        public static String constructUri(String url) {
            Uri uri = Uri.parse(url);
            return uri.isAbsolute() ? url : URI_PREFIX + url;
        }

        @Override
        public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
            File file = new File(uri.getPath());
            ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
            return parcel;
        }

        @Override
        public boolean onCreate() {
            return true;
        }

        @Override
        public int delete(Uri uri, String s, String[] as) {
            throw new UnsupportedOperationException("Not supported by this provider");
        }

        @Override
        public String getType(Uri uri) {
            throw new UnsupportedOperationException("Not supported by this provider");
        }

        @Override
        public Uri insert(Uri uri, ContentValues contentvalues) {
            throw new UnsupportedOperationException("Not supported by this provider");
        }

        @Override
        public Cursor query(Uri uri, String[] as, String s, String[] as1, String s1) {
            throw new UnsupportedOperationException("Not supported by this provider");
        }

        @Override
        public int update(Uri uri, ContentValues contentvalues, String s, String[] as) {
           throw new UnsupportedOperationException("Not supported by this provider");
        }
    }
滥情稳全场 2024-10-01 04:46:10

您必须为您的图像创建一个 ContentProvider

You have to create a ContentProvider for your images

破晓 2024-10-01 04:46:10

AFAIK,写入 SDCard 拳头是唯一的方法......并且这是必要的,因为邮件客户端必须能够读取该文件;因此,它必须存放在公共场所。

AFAIK, writting to the SDCard fist is the only way to do it... and it's necessary since the mail client has to be able to read the file; so, it has to be stored on a public place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文