我想在我的應用程序在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試試這可能是工作 –