Java 将Uri另存为文件

Java 将Uri另存为文件,java,android,uri,Java,Android,Uri,因此,在我的应用程序中,它从另一个应用程序接收图像 Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { handleSendImage(intent); // Handle s

因此,在我的应用程序中,它从另一个应用程序接收图像

      Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        handleSendImage(intent); // Handle single image being sent

public void handleSendImage(Intent a)
{
    Uri pic = (Uri) a.getParcelableExtra(Intent.EXTRA_STREAM);
}
在这里,我想将Uri保存为图像库中的图像。
我知道如何在图库中保存文件,只是不知道如何以正确的格式获取Uri来保存它。我知道它包含图像,因为
picView.setImageURI(pic)使图片显示在“我的活动”中。我只想把这张照片保存到图库里。我该怎么做有什么想法吗?我认为我可以将ImageView转换为位图,然后从那里开始,但这对我来说效率很低,必须有更好的方法。因为我知道您可以从文件创建Uri,但是您可以从Uri创建文件吗?

您在其中传递了图像或路径之类的数据?您正在检索
Intent.EXTRA_STREAM
但您没有传递任何内容。我正在将保存uri的Intent传递给handleSendImage,而在handleSendImage中,我正在检索带有
uri pic=(uri)a.getParcelableExtra(Intent.EXTRA_STREAM)的照片的数据