1

我正在开发一个应用程序,我正在使用 EditText 字段( textArea.setDrawingCacheEnabled(true); textArea.buildDrawingCache(true);)生成图像并将其保存在 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

    }
4

1 回答 1

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)));

这应该为您解决问题。

于 2013-02-02T09:08:22.410 回答