将图像发送到 Android 消息应用

Send image to Android Message app

我有一个自定义键盘,我需要在其中发送图像而不是文本(最好仅当用户在消息应用程序中时)...但我有点不确定如何具体发送图像到当前 app/activity...

所以我现在所拥有的是,当用户在我的自定义键盘上点击我的一张图片时,我 运行 以下内容:

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

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

终于成功了!

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