与Android的意图分享图像 [英] Share image with Android intent

查看:100
本文介绍了与Android的意图分享图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果
我想分享图片低谷份额的意图是这样的:


I'm trying to share an image trough a share intent like this:

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);

    sharingIntent.setType("image/png");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, application.getString(R.string.app_name));
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,application.getString(R.string.app_share_message));

    File image = new File(Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.icon_to_share).toString());
        sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));
        shareMe(sharingIntent);

份额的意图火灾正确,我选择的Gmail,一切运行如预期,直到我preSS发送。我收到通知无法显示附加和电子邮件没有它送...
为什么呢?

The share intent fires correctly and I choose Gmail, everything runs as expected until I press send. I receive a notification "Unable to show attach", and the e-mail is sent without it... Why?

感谢您的时间。

推荐答案

首先,不能保证任何其他应用程序将能够支持安卓资源// 乌里。您将有更大的兼容性共享外部存储上的文件或使用的ContentProvider

First, there is no guarantee that any given other app will be able to support an android:resource// Uri. You will have greater compatibility sharing a file on external storage or using a ContentProvider.

话虽这么说,替换:

File image = new File(Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.icon_to_share).toString());
    sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));

    sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.icon_to_share);

这是安卓资源:// 不是文件,也许你是搞乱你的乌里通过转换为一个文件然后再返回到一个乌里

An android:resource:// is not a File, and probably you are messing up your Uri by converting to a File and then back to a Uri.

这篇关于与Android的意图分享图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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