Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

android studio - Share Image From URL to Social Apps

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...