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

  • Home
  • SEARCH
  • 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 8014811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:03:39+00:00 2026-06-04T20:03:39+00:00

I have got an image path that I want to store in the shared

  • 0

I have got an image path that I want to store in the shared preferences.

  1. How do I store the path inside the shared preferences?
  2. How can I retrieve the image path from the shared preferences?
  • 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-04T20:03:40+00:00Added an answer on June 4, 2026 at 8:03 pm

    All you have to do is, convert your image to it’s Base64 string representation:

    Bitmap realImage = BitmapFactory.decodeStream(stream);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    realImage.compress(Bitmap.CompressFormat.JPEG, 100, baos);   
    byte[] b = baos.toByteArray(); 
    
    String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
    textEncode.setText(encodedImage);
    
    SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this);
    Editor edit=shre.edit();
    edit.putString("image_data",encodedImage);
    edit.commit();
    

    and then, when retrieving, convert it back into bitmap:

    SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this);
    String previouslyEncodedImage = shre.getString("image_data", "");
    
    if( !previouslyEncodedImage.equalsIgnoreCase("") ){
        byte[] b = Base64.decode(previouslyEncodedImage, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
        imageConvertResult.setImageBitmap(bitmap);
    }
    

    However, I have to tell you that Base64 support is only recently included in API8. To target on lower API version, you need to add it first. Luckily, this guy already have the needed tutorial.

    Also i have to tell you that this is a complex procedure and shareprefrence use only to store small amount of data such as user name and password that’s way you can also use such a method:

    store image path (from sdcard) into Share preferences like this–

    SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this);
    Editor edit=shre.edit();
    edit.putString("imagepath","/sdcard/imh.jpeg");
    edit.commit();
    

    To load your image path you can use this

    final SharedPreferences sharedPreference = getSharedPreferences(
                    "pref_key", MODE_PRIVATE);
            if (sharedPreference.contains("imagepath")) {
                String mFilePath = sharedPreference.getString(imagepath,
                        null);
            }
    

    After getting you path you can use:

    File imgFile = new  File(mFilePath);
    if(imgFile.exists()){
    
        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
    
        ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
        myImage.setImageBitmap(myBitmap);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got an ActiveX Control that gets an image from a fingerprint device
I'm trying to build the simple layout that I have got in the image
I have a user control that's got an image ..when I added it to
I have currently got imagepaths stored within the database and image files stored in
Have got an NSString *str = @12345.6789 and want to find out if there
I have got a Wavecom Supreme GSM modem. I wrote a simple application that
I have got a field that has been setup to allow for Null, but
I have got a demo script that lets me authorize with my app and
I have this webpage that I want to post to my profile in FB.
I've got a legacy application that is launched from an HTA . I'm starting

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.