i want to share image which is taken from my website using json, i need to download image and than share , currently i am using this method but its not working , i am not familiar with Glide and Bitmap, Please Help
here is my code :
Glide.with(context)
.asBitmap()
.load(imageUrl)
.apply(new RequestOptions()
.placeholder(R.drawable.ic_placeholder)
.diskCacheStrategy(DiskCacheStrategy.DATA))
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
}
public void onLoadFailed(@Nullable Drawable errorDrawable) {
}
});
And Bitmap code
private class ShareTask extends AsyncTask<Bitmap, Void, File> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected File doInBackground(Bitmap... params) {
try {
File cachePath = new File(context.getCacheDir(), AppConstants.TEMP_PATH);
if (!cachePath.exists()) {
cachePath.mkdirs();
}
FileOutputStream stream = new FileOutputStream(cachePath + "/" + AppConstants.TEMP_PNG_NAME);
params[0].compress(Bitmap.CompressFormat.PNG, 100, stream);
stream.close();
return cachePath;
} catch (IOException ex) {
return null;
}
}
@Override
protected void onPostExecute(@Nullable File result) {
// share wallpaper
File newFile = new File(result, AppConstants.TEMP_PNG_NAME);
Uri uri = FileProvider.getUriForFile(context, getContext().getResources().getString(R.string.fileprovider), newFile);
launchShareIntent(uri);
}
}
share Intent
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setDataAndType(uri, mActivity.getContentResolver().getType(uri));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType(mActivity.getContentResolver().getType(uri));
context.startActivity(Intent.createChooser(shareIntent, getContext().getResources().getString(R.string.share_wallpaper_title)));
and Bitmap load image
public void shareWallpaper() {
if (mBitmap != null) {
new ShareTask().execute(mBitmap);
} else {
Toast.makeText(context, getContext().getResources().getString(R.string.wallpaper_not_loaded), Toast.LENGTH_SHORT).show();
}
}
question from:
https://stackoverflow.com/questions/65885845/download-image-using-glide-and-bitmap-and-share 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…