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 8370623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:57:27+00:00 2026-06-09T13:57:27+00:00

I have an Activity where the user can share an image from the raw

  • 0

I have an Activity where the user can share an image from the raw folder.

The raw folder has 70 images, all named alphabetically. The first one is R.raw.recipe01 and the last is R.raw.recipe70.

I get the image int I would like to share from a Bundle and I have a method which copies the image from the raw folder to a accessible file.

I call startActivity(createShareIntent()); in the ActionBar MenuItem, which works successfully.

PROBLEM

The share intent will always select R.raw.recipe01 as the image, even if the int from the Bundle is for image for exmaple R.raw.recipe33.

I have shared my code below. Can anyone spot what I am doing wrong?

CODE:

private int rawphoto = 0;
private static final String SHARED_FILE_NAME = "shared.png";

@Override
public void onCreate(Bundle savedInstanceState) {

    Bundle bundle = getIntent().getExtras();
    rawphoto = bundle.getInt("rawphoto");
    int savedphoto = rawphoto;

    // COPY IMAGE FROM RAW
    copyPrivateRawResourceToPubliclyAccessibleFile(savedphoto);


private Intent createShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    shareIntent.putExtra(Intent.EXTRA_TEXT, "IMAGE TO SHARE: ");
    Uri uri = Uri.fromFile(getFileStreamPath("shared.png"));
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

    return shareIntent;
}


private void copyPrivateRawResourceToPubliclyAccessibleFile(int photo) {

    System.out.println("INT PHOTO: " +photo);

    InputStream inputStream = null;
    FileOutputStream outputStream = null;
    try {
        inputStream = getResources().openRawResource(photo);
        outputStream = openFileOutput(SHARED_FILE_NAME,
                Context.MODE_WORLD_READABLE | Context.MODE_APPEND);
        byte[] buffer = new byte[1024];
        int length = 0;
        try {
            while ((length = inputStream.read(buffer)) > 0) {
                outputStream.write(buffer, 0, length);
            }
        } catch (IOException ioe) {
            /* ignore */
        }
    } catch (FileNotFoundException fnfe) {
        /* ignore */
    } 

    finally {
        try {
            inputStream.close();
        } catch (IOException ioe) {

        }
        try {
            outputStream.close();
        } catch (IOException ioe) {

        }
    }

}
  • 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-06-09T13:57:28+00:00Added an answer on June 9, 2026 at 1:57 pm

    Remove Context.MODE_APPEND so that the file gets overwritten if it already exists.

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

Sidebar

Related Questions

I have 4 activities. A,B,C and D. From each activity user can start any
I have the following problem: I have an Activity where a user can start
i have a default activity that starts first (Activity A), and from there the
Specfically, I have an activity that can be called from the homescreen, OR can
I have an activity that starts on demand of the user. The user can
I have models called User , Activity , and Task and I can do
I have a Properties Activity where the user has to provide some data to
The application I'm working on has an activity feed where each user can see
I want to retrieve data from sqlite. user can have more than 1 score
I have a multiple Activity application that progresses the user from entering an IP/Host

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.