Android的份额文字和图片份额、文字、图片、Android

2023-09-07 15:26:08 作者:荣辱兴亡盛衰

我需要通过Facebook,电子邮件等分享文字+图像现在,我用这个code:

I need to share text+image via Facebook, email etc. Now, I use this code:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.settings_share_text));
//Uri path = Uri.parse("android.resource://com.android.mypackage/" + R.drawable.arrow);
Uri path = Uri.parse("android.resource://com.android.mypackage/drawable/arrow.png");
intent.putExtra(Intent.EXTRA_STREAM, path );
Intent mailer = Intent.createChooser(intent, null);
startActivity(mailer);

现在的问题是,当我用arrow.png,它说:无法显示附件,不重视形象;当我删除巴纽,我无法打开后附加的文件。 基本上,我需要通过ACTION_SEND的绘制和一些文字附加PNG和分享

The problem is that when I use "arrow.png", it says "Couldn't show attachment" and doesn't attach image; when I remove .png, I cannot open attached file later. Basically, I need to attach png from drawable and some text and share it via ACTION_SEND

推荐答案

尝试使用

Uri.fromFile(new File("android.resource://com.android.mypackage/drawable/arrow.png"));

的insted的

insted of

Uri.parse("android.resource://com.android.mypackage/drawable/arrow.png");

这将正常工作,如果文件描述符将是有效的。

It will work fine if file descriptor will be valid.