0

我有一个应用程序,其中有一个电子邮件部分,我必须在正文中输入文本和图像。我在网上搜索但没有找到相应的解决方案。任何帮助将不胜感激。

这是视图:

谷歌电子邮件/默认电子邮件客户端

4

1 回答 1

1
BitmapFactory.Options bitmapFatoryOptions=new BitmapFactory.Options();
        bitmapFatoryOptions.inPreferredConfig=Bitmap.Config.ARGB_8888;
Bitmap myBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.face4,bitmapFatoryOptions);

 File  mFile = savebitmap(myBitmap);
        Uri u = null;
        u = Uri.fromFile(mFile);
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType("image/*");
   Intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Send Mail");
        emailIntent.putExtra(Intent.EXTRA_TEXT,  getString(R.string.share_texthere));
        emailIntent.putExtra(Intent.EXTRA_STREAM, u);
        startActivity(Intent.createChooser(emailIntent,"Send"));

saveBitmap() 方法的代码:

    private File savebitmap(Bitmap bmp) {
    String temp="SplashItShare";
    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
    OutputStream outStream = null;
    String path = Environment.getExternalStorageDirectory()
            .toString();
    new File(path + "/SplashItTemp").mkdirs();
    File file = new File(path+"/SplashItTemp", temp + ".png");
    if (file.exists()) {
        file.delete();
        file = new File(path+"/SplashItTemp", temp + ".png");
    }

    try {
        outStream = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream);
        outStream.flush();
        outStream.close();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return file;
}

希望它对你有用。

于 2013-07-24T09:38:37.667 回答