android - 将图像共享到其他应用程序

标签 android image share

在我的应用程序中,我可以获取屏幕截图并将其保存到 SD 卡。我想知道是否可以将其从我的应用程序共享到 Whatsapp,例如,就像图库应用程序那样。

在图库中,您有机会将文件“共享”到 Whatsapp、Facebook 或 Twitter。

我可以在我的应用程序中执行同样的操作吗?怎么办?

谢谢!

最佳答案

是的,可以。

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@SuppressWarnings( "deprecation" )
public static Intent shareImage(Context context, String pathToImage) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    else
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);

    shareIntent.setType("image/*");

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

这里有详细链接:http://android-developers.blogspot.com/2012/02/share-with-intents.html

因此,只需添加一个“共享”按钮并执行 startActivity(shareIntent)

关于android - 将图像共享到其他应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12236778/

相关文章:

android - 可绘制文件夹中图像的 dpi

android - 如何创建从 viewpager2 扩展的自定义 View ?

android - 在 android.app.AlertDialog 和 android.support.v7.app.AlertDialog 之间选择

c# - 设置图像时参数无效

android - 如何让我的 Android 应用出现在另一个特定应用的共享列表中

Android ContextMenu 如何设置TextColor 和背景颜色?

swift - 使用 Firebase 存储数据库填充 TableView

iphone - 如何通过 iPhone App 在 linkedin 上分享文本/网址?

javascript - LinkedIn 分享回调 Javascript SDK/API v2

jquery - 将图像屏蔽成多个部分,而无需多次加载图像