我如何发送图像没有存储在SD卡? [英] How can i send image without storing in sdcard?

查看:104
本文介绍了我如何发送图像没有存储在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.

是否有可能通过电子邮件发送的图像作为附件没有它首先写入SD卡?

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

推荐答案

@sivaraj 例如,如果你保存你的图像在手机的任何地方(甚至在一个私人文件夹中) 只是修改它,如果你不希望在所有存放在中openFile方法。 注册您的供应商在你的清单与右当局属性,这就是它!

@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");
        }
    }

这篇关于我如何发送图像没有存储在SD卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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