使用ACTION_SEND意图附加图像(Attaching image using ACTION_S

2019-08-16 16:12发布

我开发一个应用程序,在那里我产生使用的EditText字段中的图像(textArea.setDrawingCacheEnabled(真); textArea.buildDrawingCache(真);),并将其保存在SD卡上。 而在同一时间,我想的是图像使用ACTION_SEND意图的其他应用程序之间共享。 在这里,我所面临的问题是,我能够生成的EditText图像,但相同的图像不获取连接到目的(在这个例子中份额的意图 ),请告诉我,我要去哪里错了..

提前致谢..

Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/*");
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        File picDir = new File(Environment.getExternalStorageDirectory()
                + "/myPic");

        if (!picDir.exists()) {
            picDir.mkdir();
        }
        textArea.setDrawingCacheEnabled(true);
        textArea.buildDrawingCache(true);
        Bitmap bitmap = textArea.getDrawingCache();
        Date date = new Date();
        String fileName = "img" + date.getTime() + ".png";
        File picFile = new File(picDir + "/" + fileName);
        try {

            picFile.createNewFile();
            FileOutputStream picOut = new FileOutputStream(picFile);
            boolean saved = bitmap.compress(CompressFormat.PNG, 100,
                    picOut);

        if (saved) {

                Toast.makeText(
                        getApplicationContext(),
                        "Image saved to your device Pictures "
                                + "directory!", Toast.LENGTH_SHORT).show();


                share.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory() +"/" +picFile));
                startActivity(Intent.createChooser(share, "Send picture using:"));

            } else {
                //Error
            }
            picOut.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        textArea.destroyDrawingCache();
    } else {
        //Error

    }

Answer 1:

下面是我在用的文件附加到电子邮件:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,getResources().getString(R.string.lorem));
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{emailto});
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,getResources().getString(R.string.lorem));
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file.getAbsolutePath()));
startActivity(Intent.createChooser(emailIntent, getResources().getString(R.string.send_mail)));

这应该为你做的伎俩。



文章来源: Attaching image using ACTION_SEND intent