Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6114651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:59:57+00:00 2026-05-23T14:59:57+00:00

i am trying to share an image from the drawables in my application. i

  • 0

i am trying to share an image from the drawables in my application. i keep getting java.io.FileNotFoundException:/abc.jpg (read-only file system)

my code is

  private String SaveCache(int resID) {
            String path = "";  
            try {
                InputStream is = getResources().openRawResource(resID);
                File cacheDir = this.getExternalCacheDir();
                File downloadingMediaFile = new File(cacheDir, "abc.jpg");
                byte[] buf = new byte[256];
                FileOutputStream out = new FileOutputStream(downloadingMediaFile);   
                while (true) {
                    int rd = is.read(buf, 0, 256);
                    if (rd == -1 || rd == 0)
                        break;
                    out.write(buf, 0, rd);              
                }
                is.close();
                out.close();
                return downloadingMediaFile.getPath();
            } catch (Exception ex) {
                Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
                ex.printStackTrace();
            }
            return path;
        }



        private void ImageShare() {
            String path = SaveCache(R.drawable.testsend);
            Toast.makeText(this, path, Toast.LENGTH_LONG).show();
            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("image/jpeg");
            share.putExtra(Intent.EXTRA_SUBJECT, "test");
            share.putExtra(Intent.EXTRA_TEXT, "test");
            share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + path));       
            try {
                startActivity(Intent.createChooser(share, "Choose share method."));
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        }

Any help is appreciated, if more info is required i will be happy to provide.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:59:58+00:00Added an answer on May 23, 2026 at 2:59 pm

    Make sure that the external storage is mounted.

    From the docs of getExternalCacheDir():

    Returns the path of the directory holding application cache files on
    external storage. Returns null if external storage is not currently
    mounted so it could not ensure the path exists; you will need to call
    this method again when it is available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to share a single httpd.conf file across multiple OS X machines. I'm
Im trying to download share data from a stock exchange using python. The problem
i am trying to programmatically attach an image to an email body from my
Trying to implement the example from here. Facebook Share passes along the URL of
I'm trying to send an image from C++ to C# with an interop (marshaling)
I have a web application that is trying to access images from a shared
I'm trying to integrate facebook share by using images directly from my database. Static
I'm trying to expose a .png file located in my application's /data directory through
I'm trying to integrate facebook share by using images directly from my database. Static
I am trying to make a application where a dialog will come from where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.