安卓:当HTC Hero的选择Gmail应用Intent.ACTION_SEND与EXTRA_STREAM不附加任何图像 [英] Android: Intent.ACTION_SEND with EXTRA_STREAM doesn't attach any image when choosing Gmail app on htc Hero

查看:181
本文介绍了安卓:当HTC Hero的选择Gmail应用Intent.ACTION_SEND与EXTRA_STREAM不附加任何图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个默认的邮件应用程序模拟器一切工作正常。但我我'收到,我已经从使用Gmail应用程序我的英雄发送邮件时,没有附上。对英雄的默认邮件应用程序工作正常。

On the Emulator with a default mail-app all works fine. But I have no attach when I'am receiving a mail which I've sent from my Hero using a Gmail app. The default Mail app on the hero works fine.

我怎样才能让这个code工作与英雄的Gmail应用程序?
你可以看到下面的code。

How can I make this code works with Gmail app on Hero?
You can see the code below.

    private void startSendIntent() {
        Bitmap bitmap = Bitmap.createBitmap(editableImageView.getWidth(), editableImageView.getHeight(), Bitmap.Config.RGB_565);
        editableImageView.draw(new Canvas(bitmap));
        File png = getFileStreamPath(getString(R.string.file_name));
        FileOutputStream out = null;
        try {
            out = openFileOutput(getString(R.string.file_name), MODE_WORLD_READABLE);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (out != null) out.close();
            }
            catch (IOException ignore) {}
        }
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(png));
        emailIntent.setType("image/png");
        startActivity(Intent.createChooser(emailIntent, getString(R.string.send_intent_name)));
}

在日志中我看到以下内容:

in Logs I see the following:

02-05 17:03:37.526: DEBUG/Gmail(11511): URI FOUND:file:///sdcard/DCIM/100MEDIA/IMAG0001.jpg
02-05 17:03:37.535: DEBUG/Gmail(11511): ComposeActivity added to message:0 attachment:|IMAG0001.jpg|image/jpeg|0|image/jpeg|LOCAL_FILE|file:///sdcard/DCIM/100MEDIA/IMAG0001.jpg size:0
02-05 17:03:37.585: INFO/Gmail(11511): >>>>> Attachment uri: file:///sdcard/DCIM/100MEDIA/IMAG0001.jpg
02-05 17:03:37.585: INFO/Gmail(11511): >>>>>           type: image/jpeg
02-05 17:03:37.585: INFO/Gmail(11511): >>>>>           name: IMAG0001.jpg
02-05 17:03:37.585: INFO/Gmail(11511): >>>>>           size: 0

感谢您的回答。

推荐答案

有关我的问题解决了与code以下行:

For me the problem was solved with the following lines of code:

Bitmap screenshot = Bitmap.createBitmap(_rootView.getWidth(), _rootView.getHeight(), Bitmap.Config.RGB_565);
_rootView.draw(new Canvas(screenshot));

String path = Images.Media.insertImage(getContentResolver(), screenshot, "title", null);
Uri screenshotUri = Uri.parse(path);

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
emailIntent.setType("image/png");

startActivity(Intent.createChooser(emailIntent, "Send email using"));

最关键的一点是,我节省了屏幕截图到媒体库中,然后就可以成功地从那里发送文件。

The key thing is that I'm saving the screen-shot to the media library and then it can successfully send a file from there.

这篇关于安卓:当HTC Hero的选择Gmail应用Intent.ACTION_SEND与EXTRA_STREAM不附加任何图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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