Search code examples
androidimageuriandroid-sharing

Android sharing image not working


I'm trying to share an image in an app I have made that downloads an Image and writes it to a file. But any time I try to share it, it says can't upload file or just does nothing. It's not coming up in the logcat so I'm kinda stuck for ideas on how to fix it.

The image that is downloaded is displayed in an image view like this

        iView.setImageBitmap(im);
        String path = ContentFromURL.Storage + "/temp.jpg";
        File temp = new File(path);
        uri = Uri.fromFile(temp);
        iView.setImageURI(uri);

Asynch task to download file

    HttpURLConnection connection;
    try {
        String url = params[0];
        connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setRequestProperty("Accept-Charset","UTF-8");
        connection.connect();
        InputStream input = connection.getInputStream();
        image = BitmapFactory.decodeStream(input);
        File temp = new File(Storage,"temp.jpg");
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        image.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
        FileOutputStream fo = new FileOutputStream(temp);
        fo.write(bytes.toByteArray());
        fo.close();
        String path = temp.getAbsolutePath();
        Log.d("Asynch", "image shuould exist");
        SharePage.act.runOnUiThread(new Runnable()
        {
            public void run()
            {
                SharePage.setImage(image);
            }
        }
        );

creating intent

    twitterIntent = new Intent(Intent.ACTION_SEND);
    twitterIntent.setClassName("com.twitter.android",packageName);
    twitterIntent.setType("image/jpeg");
    twitterIntent.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(twitterIntent);

I know that I should use the built in android share thing but its not working either when I try to share the image


Solution

  • The problem was where I was trying to store the Image, I wanted to have it so that the user never saw the image and it was deleted when it wasn't needed anymore but the other apps didn't have access to the directory. So I have since moved it to the external storage directory.