我有一个共享按钮,它将共享带有文本的drawable的图像。从Drawable获取PNG的URI返回没有任何文件扩展名的空白文件
public boolean shareGame(String msg) {
if (Configuration.Share_WITH_IMAGE) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/png");
Uri uri = Uri
.parse("android.resource://" + getPackageName() + "/" + R.drawable.share_image);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.putExtra(Intent.EXTRA_TEXT, msg + " " + GOOGLE_PLAY_URL);
startActivity(Intent.createChooser(shareIntent, "Share: " + msg));
} else {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, msg + GOOGLE_PLAY_URL);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, msg));
}
return true;
}
目前,当我尝试通过电子邮件分享时,它会返回一个没有任何扩展名的空文件。 WhatsApp共享给出了不支持的文件类型的错误。
我是否需要将其转换为位图?如果是这样,那么最好的办法是什么。
谢谢。
'android.resource'是一个很少使用的'Uri'方案。某些应用程序可能不会期望它,并可能在使用它时遇到问题“我需要将其转换为位图吗?” - 不,因为“ACTION_SEND”不支持“位图”。您可能希望使用“ContentProvider”来提供图像。 – CommonsWare