共享图像到另一个应用程序 [英] Share images to another apps

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

问题描述

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

In my app I can get a screen capture and save it to the sd card. I was wondering if it's possible to share it from my app to Whatsapp, for example, as the gallery app does.

在画廊中,您可以将文件共享"到Whatsapp,Facebook或Twitter.

In the gallery, you have the chance of "sharing" the file to Whatsapp, Facebook or Twitter.

我可以通过我的应用程序执行同样的操作吗?怎么样?

Can i do the same from my app? How?

谢谢!

推荐答案

是的,可以.

@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).

So just add a "share" button and execute startActivity(shareIntent).

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

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