简体   繁体   English

与其他应用分享图片

[英]Share image with other apps

Here is my problem... I want to share a png image. 这是我的问题......我想分享一个png图像。 I have the image in drawable and assets. 我有可绘制和资产的图像。 When I use the sharingIntent it works but not in the way that I want. 当我使用sharingIntent它工作但不是我想要的方式。 The file shared appears with numbers and without extension and some apps send the message "unknow file". 共享的文件显示为数字而没有扩展名,一些应用程序发送消息“未知文件”。 What can i do?? 我能做什么??

this is my code: 这是我的代码:

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

I tried to use instead of drawable files, the files in assets ( with this " file:///android_asset/... ) but it didn't work 我尝试使用而不是可绘制文件,资产中的文件(使用此文件:/// android_asset / ... )但它不起作用

Try something like this: 尝试这样的事情:

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)

If you want to share it via the assets folder, you'll have to use a ContentProvider. 如果要通过assets文件夹共享它,则必须使用ContentProvider。 See this answer on how to do so: 请参阅此答案,了解如何执行此操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM