我想在我的应用程序在Instagram上分享图像。我有图像的网址,并使用毕加索图书馆下载图像。Android:加载图像与毕加索onBitMapLoaded不叫
Target target = new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
Log.d(TAG, "Bitmap Loaded");
File outputDir = getApplicationContext().getCacheDir(); // context being the Activity pointer
try {
File outputFile = File.createTempFile("instagram", "png", outputDir);
outputFile.createNewFile();
FileOutputStream ostream = new FileOutputStream(outputFile);
bitmap.compress(Bitmap.CompressFormat.JPEG,100,ostream);
ostream.close();
Log.d(TAG, "Image downloaded");
shareOnInstagram(Uri.fromFile(outputFile));
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(this).load(imageUrl).into(target);
但onBitmapLoaded永远不会被调用。有没有其他方式可以通过网址分享Instagram上的图片?在Instagram上分享的意图需要Intent.EXTRA_STREAM
参数,其参数应该是media path on device
。 如何将图片从网址转换为该类型?
http://stackoverflow.com/a/43134498/5488468试试这可能是工作 –