找到你要的答案

Q:Sharing content

Q:共享内容

I have a gridview, clicking any image in the gridview expands it to a bigger image view, in this image view i can swipe left and right to change my images, i have added a method that would let me share the image to other apps like facebook watsapp etc. But the method seems to be not quite right, i cant figure out my mistake. It opens the popup window showing options to share the image but when i choose any option to send the image it says, Couldn't Load The Image.

Have a look at my code:

else {



                    if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE
                                && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {

                            URL url2 = new URL((thumb[j]));
                            Bitmap bimage = BitmapFactory.decodeStream(url2
                                    .openConnection().getInputStream());
                            shareImage();

                            Toast.makeText(getApplicationContext(),
                                    "Saving to Favorites", Toast.LENGTH_LONG)
                                    .show();



                        }

                    }

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return false;
        }

    }



    private void shareImage() {
        Intent share = new Intent(Intent.ACTION_SEND);

        // If you want to share a png image only, you can do:
        // setType("image/png"); OR for jpeg: setType("image/jpeg");
        share.setType("image/*");

        // Make sure you put example png image named myImage.png in your
        // directory
        String bimage = Environment.getExternalStorageDirectory()
                + thumb[j];

        File imageFileToShare = new File(bimage);

        Uri uri = Uri.fromFile(imageFileToShare);
        share.putExtra(Intent.EXTRA_STREAM, uri);

        startActivity(Intent.createChooser(share, "Share Image!"));
    }
}

Whereas thumb is the array having all the resource ids of the image, "j" is the int who's value initiated to 0.

Using the gesture to initiate the code.

I am ready to share my full code for greater understanding.

Any help would highly be appreciated.

我有一个GridView控件,单击GridView中的任何图像扩展到一个更大的图像,这个图像查看我可以刷卡离开,改变我的形象,我添加了一个方法可以让我分享图像到其他应用程序如脸谱网WatsApp等但方法似乎是不正确的,我不知道是我的错。打开弹出窗口显示选项共享图像但当我选择任何选项将图像表示,无法加载图像。

看看我的代码:

else {



                    if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE
                                && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {

                            URL url2 = new URL((thumb[j]));
                            Bitmap bimage = BitmapFactory.decodeStream(url2
                                    .openConnection().getInputStream());
                            shareImage();

                            Toast.makeText(getApplicationContext(),
                                    "Saving to Favorites", Toast.LENGTH_LONG)
                                    .show();



                        }

                    }

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return false;
        }

    }



    private void shareImage() {
        Intent share = new Intent(Intent.ACTION_SEND);

        // If you want to share a png image only, you can do:
        // setType("image/png"); OR for jpeg: setType("image/jpeg");
        share.setType("image/*");

        // Make sure you put example png image named myImage.png in your
        // directory
        String bimage = Environment.getExternalStorageDirectory()
                + thumb[j];

        File imageFileToShare = new File(bimage);

        Uri uri = Uri.fromFile(imageFileToShare);
        share.putExtra(Intent.EXTRA_STREAM, uri);

        startActivity(Intent.createChooser(share, "Share Image!"));
    }
}

而拇指的阵列具有图像的所有资源ID,“J”是int值是谁发起的0。

使用手势启动代码。

我已经准备好分享我的完整代码以获得更大的理解。

任何帮助将高度赞赏。

answer1: 回答1:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    Uri screenshotUri = Uri.parse(Images.Media.EXTERNAL_CONTENT_URI + "/" + imageIDs);

    sharingIntent.setType("image/jpeg");
    sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
    startActivity(Intent.createChooser(sharingIntent, "Share image using")); 
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    Uri screenshotUri = Uri.parse(Images.Media.EXTERNAL_CONTENT_URI + "/" + imageIDs);

    sharingIntent.setType("image/jpeg");
    sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
    startActivity(Intent.createChooser(sharingIntent, "Share image using")); 
android  facebook