1.创建的一个文件

mZipFile = new File(Paths
                                                .pageBitmapPath()
                                                + "/test.zip");
                                        if (!mZipFile.exists()) {
                                            try {
                                                mZipFile.createNewFile();
                                            } catch (IOException e) {
                                                // TODO Auto-generated catch
                                                // block
                                                e.printStackTrace();
                                            }
                                        }

2.通过系统自带的蓝牙或者邮件发送出文件 intent

Intent intent = new Intent(
                                                Intent.ACTION_SEND);
                                        intent.putExtra("subject", mZipFile
                                                .getName()); //
                                        intent.putExtra("body", "发送的内容:"); // 正文
                                        intent.putExtra(Intent.EXTRA_STREAM,
                                                Uri.fromFile(mZipFile)); // 添加附件,附件为file对象
                                        if (mZipFile.getName().endsWith(".gz")) {
                                            intent
                                                    .setType("application/x-gzip"); // 如果是gz使用gzip的mime
                                        } else if (mZipFile.getName().endsWith(
                                                ".txt")) {
                                            intent.setType("text/plain"); // 纯文本则用text/plain的mime
                                        } else if (mZipFile.getName().endsWith(
                                                ".zip")) {
                                            intent.setType("application/zip"); // 纯文本则用text/plain的mime
                                        } else {
                                            intent
                                                    .setType("application/octet-stream"); // 其他的均使用流当做二进制数据来发送
                                        }
                                        getContext().startActivity(
                                                Intent.createChooser(intent,
                                                        "选择邮件客户端"));

 

具体的效果图如下图所示:

image

4.选择了邮件发送:

image