gpt4 book ai didi

android - 分享图片到其他应用

转载 作者:搜寻专家 更新时间:2023-11-01 09:05:24 26 4
gpt4 key购买 nike

在我的应用程序中,我可以获得屏幕截图并将其保存到 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com