i want to share images from url to different social apps. i am trying with below code but its saying "The File Format Not Supported"
this is my code:
@Override
public void onClick(View view) {
File file = writebitmaptofilefirst("the_new_image","https://www.punjabidharti.com/images/down.png");
Uri uri = Uri.fromFile(file);
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
context.startActivity(Intent.createChooser(shareIntent, "Share image using"));
}
public static File writebitmaptofilefirst(String filename, String source) {
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File mFolder = new File(extStorageDirectory + "/temp_images");
if (!mFolder.exists()) {
mFolder.mkdir();
}
OutputStream outStream = null;
File file = new File(mFolder.getAbsolutePath(), filename + ".png");
if (file.exists()) {
file.delete();
file = new File(extStorageDirectory, filename + ".png");
Log.e("file exist", "" + file + ",Bitmap= " + filename);
}
try {
URL url = new URL(source);
Bitmap bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
outStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (Exception e) {
e.printStackTrace();
}
Log.e("file", "" + file);
return file;
}
i am new to android developer, i have searched lot in google but still couldn't find the answer, i am trying for 2 weeks,
please help
question from:
https://stackoverflow.com/questions/65873204/share-image-from-url-to-social-apps 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…