Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.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_Picasso - Fatal编程技术网

Android 毕加索-获取加载图像的路径

Android 毕加索-获取加载图像的路径,android,picasso,Android,Picasso,我在Android应用程序中使用毕加索从URL加载图像。这些图像显示在一些列表视图中。当用户单击此列表视图中的某个项目时,我需要为所选图像创建共享意图 我使用以下代码创建共享意图: Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(localPath)); shar

我在Android应用程序中使用毕加索从URL加载图像。这些图像显示在一些
列表视图中。当用户单击此
列表视图中的某个项目时,我需要为所选图像创建共享
意图

我使用以下代码创建共享意图:

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(localPath));
shareIntent.putExtra(Intent.EXTRA_TEXT, mUrl);
shareIntent.setType("image/jpg");
startActivity(Intent.createChooser(shareIntent, getString(R.string.label_share)));
在上面的代码中,有一个局部变量
localPath
。此变量必须包含图像的路径。我想毕加索有一些缓存,下载的图像存储在那里。有什么方法可以检索所选图像的路径吗

更新:部分解决方案

最后,我找到了一个适合我的解决方案。但我不知道这是一个正确的解决方案,还是存在更好的解决方案

我创建了一个实现
com.squareup.picasso.Target
接口的类,并在方法
onBitmapLoaded(位图位图,LoadedFrom)
中提供了以下实现:

@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
    mImageView.setImageBitmap(bitmap);
    mImageUri = getBitmapUri(bitmap, mName));
}

private Uri getBitmapUri(Bitmap bitmap, String title) {
     ByteArrayOutputStream bytes = new ByteArrayOutputStream();
     bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
     String path = MediaStore.Images.Media.insertImage(mContext.getContentResolver(), bitmap, title, null);
     return Uri.parse(path);
}
在那之后,我有了
mimageri
,我可以将其传递给共享意图。也许这部分代码对某些人有用


但我不知道是否存在更好的解决方案。在我的解决方案中,我必须将
位图
存储在磁盘上,但可能磁盘上已经有相同的图像,因为毕加索加载了它。而且,我不知道当我不再需要图像时是否必须从
MediaStore
删除它。

您想用该路径做什么????这取决于解决方案是否可以提供,我需要图像的路径,因为我需要将其提供给共享意图。请在我的代码中查看我的
localPath
变量。@clairvoyan请不要查看我的更新。