将图像发送到Android消息应用程序

时间:2015-11-11 22:22:24

标签: android ime

我有一个自定义键盘,我需要发送一个图像而不是文本(最好只有当用户在消息应用程序中时)...但我不确定如何专门发送图像到当前的应用/活动...

所以我现在所拥有的是当用户点击我的自定义键盘中的某个图像时,我运行以下内容:

Drawable mDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.rsz_emoji, null);
Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(getContentResolver(), mBitmap, "Emoticon", null);

Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
picMessageIntent.putExtra(Intent.EXTRA_STREAM, path);
picMessageIntent.setType("image/jpeg");
Intent new_intent = Intent.createChooser(picMessageIntent, "Share via");
new_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(new_intent);

所以这打开了共享弹出窗口,但理想情况下,我想要的是将图像添加到消息中......那么有谁知道什么方法可以给我带来预期的效果?

1 个答案:

答案 0 :(得分:2)

终于搞定了!

Drawable mDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.rsz_emoji, null);
Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(getContentResolver(), mBitmap, "Emoticon", null);
Uri fileUri = Uri.parse(path);

Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
picMessageIntent.setPackage("com.android.mms");
picMessageIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
picMessageIntent.setType("image/png");
picMessageIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(picMessageIntent);