启动 ACTION_SEND 意图时如何附加位图 [英] How to attach a Bitmap when launching ACTION_SEND intent

查看:15
本文介绍了启动 ACTION_SEND 意图时如何附加位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

 Intent intent = new Intent(); 
 intent.setAction(Intent.ACTION_SEND); 
 startActivity(intent); 

这将在 Android 上成功启动消息应用程序.

Which will successfully launch a Messaging App on Android.

但是如何在启动 Intent 时附加 Bitmap 对象?

But how can I attach a Bitmap object when launching the intent?

我已阅读http://developer.android.com/reference/Android/content/Intent.html,我需要的壁橱里的东西是 EXTRA_STREAM,就像这样:

I have read http://developer.android.com/reference/Android/content/Intent.html, the closet thing to what I need is EXTRA_STREAM, like this:

intent2.putExtra(Intent.EXTRA_STREAM, _uri);

intent2.putExtra(Intent.EXTRA_STREAM, _uri);

但我的情况是,我有一个位图对象的引用,而不是位图的 URI.

But my case, I have a reference of Bitmap object, not an URI of a Bitmap.

请告诉我如何附加 Bitmap 对象?

Please tell me what to do to attach a Bitmap object?

推荐答案

    String pathofBmp = Images.Media.insertImage(getContentResolver(), bitmap,"title", null);
    Uri bmpUri = Uri.parse(pathofBmp);
    final Intent emailIntent1 = new Intent(     android.content.Intent.ACTION_SEND);
    emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent1.putExtra(Intent.EXTRA_STREAM, bmpUri);
    emailIntent1.setType("image/png");

其中位图是必须存储在 SD 卡中的位图对象.然后将该 Uri 用于 shareimage.

Where bitmap is your bitmap object which must be store in SD Card. and then use that Uri for shareimage.

这篇关于启动 ACTION_SEND 意图时如何附加位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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