与其他应用共享图像 [英] Share image with other apps

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

问题描述

这是我的问题...我想共享一个png图片.我有可绘制的图像和资产.当我使用sharedIntent时,它可以工作,但不能达到我想要的方式.共享的文件显示为数字,没有扩展名,某些应用程序发送消息"unknow file".我能做些什么??

Here is my problem... I want to share a png image. I have the image in drawable and assets. When I use the sharingIntent it works but not in the way that I want. The file shared appears with numbers and without extension and some apps send the message "unknow file". What can i do??

这是我的代码:

    Uri uri = Uri.parse("android.resource://com.example.shareimages/" + R.drawable.caja);
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);

    shareIntent.setType("image/png");

    shareIntent.putExtra(Intent.EXTRA_STREAM,  uri);

    startActivity(Intent.createChooser(shareIntent, "send"));

我尝试使用资产中的文件(带有此" file:///android_asset/... ")代替可绘制的文件,但没有用

I tried to use instead of drawable files, the files in assets ( with this "file:///android_asset/...) but it didn't work

推荐答案

尝试如下操作:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("image/*");

// For a file in shared storage.  For data in private storage, use a ContentProvider.
Uri uri = Uri.fromFile(getFileStreamPath(pathToImage));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(shareIntent)

如果要通过资产文件夹共享它,则必须使用ContentProvider.有关此操作的信息,请参见以下答案:

If you want to share it via the assets folder, you'll have to use a ContentProvider. See this answer on how to do so:

https://stackoverflow.com/a/7177103/1369222

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

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