Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将图像共享到其他应用程序_Android_Image_Share - Fatal编程技术网

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

Android 将图像共享到其他应用程序,android,image,share,Android,Image,Share,在我的应用程序中,我可以获取屏幕截图并将其保存到sd卡。我想知道是否有可能像gallery应用程序那样,将它从我的应用程序共享到Whatsapp 在图库中,您有机会将文件“共享”到Whatsapp、Facebook或Twitter 我可以从我的应用程序中执行同样的操作吗?怎么做 谢谢大家! 是的,你可以 @TargetApi(Build.VERSION_CODES.LOLLIPOP) @SuppressWarnings( "deprecation" ) public static Intent

在我的应用程序中,我可以获取屏幕截图并将其保存到sd卡。我想知道是否有可能像gallery应用程序那样,将它从我的应用程序共享到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;
}
@TargetApi(Build.VERSION\u CODES.LOLLIPOP)
@抑制警告(“弃用”)
公共静态意图共享图像(上下文上下文、字符串路径图像){
意向共享意向=新意向(意向.行动\发送);
if(Build.VERSION.SDK\u INT
以下是详细链接:


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

将这两个答案结合起来就可以了!谢谢你们

private void shareIt() {
    //sharing implementation here

    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    sharingIntent.setType("image/*");

    Uri uri = Uri.fromFile(file);
    sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);

    startActivity(Intent.createChooser(sharingIntent, "Share via"));

    }