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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:14:25+00:00 2026-06-05T10:14:25+00:00

i have tried this code to upload an image from gallery to sqllite database

  • 0

i have tried this code to upload an image from gallery to sqllite database in my application but when my application tries to open gallery it gives FORCE TO CLOSE Error and i dont know what is the problem.help me and thanx in advanced

public class ImagggggggActivity extends Activity { 

    private static final int SELECT_PICTURE = 1;
    private String selectedImagePath; 
    private ImageView img; 

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);    
        setContentView(R.layout.main);  

         ((Button) findViewById(R.id.button1)) 
         .setOnClickListener(new OnClickListener() { 

             public void onClick(View arg0) { 

                 // in onCreate or any event where your want the user to 
                 // select a file 
                 Intent intent = new Intent(); 
                 intent.setType("image/*"); 
                 intent.setAction(Intent.ACTION_GET_CONTENT); 
                 startActivityForResult(Intent.createChooser(intent, 
                         "Select Picture"), SELECT_PICTURE); 
             } 
         }); 
} 

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
 if (resultCode == RESULT_OK) { 
     if (requestCode == SELECT_PICTURE) { 
         Uri selectedImageUri = data.getData(); 
         selectedImagePath = getPath(selectedImageUri); 
     } 
 } 
} 

public String getPath(Uri uri) { 
 String[] projection = { MediaStore.Images.Media.DATA }; 
 Cursor cursor = managedQuery(uri, projection, null, null, null); 
 int column_index = cursor 
         .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
 cursor.moveToFirst(); 
 return cursor.getString(column_index); 
}}
  • 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-05T10:14:27+00:00Added an answer on June 5, 2026 at 10:14 am

    Import form device by button click

    Intent sdintent = new Intent(Intent.ACTION_PICK);
    sdintent.setType("image/*");
    startActivityForResult(sdintent, SD_REQUEST);
    

    Get image form sd card

    if (requestCode == SD_REQUEST) {
    Uri selectedImage = data.getData();
    String[] filePathColumn = { MediaStore.Images.Media.DATA };
    
    Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
    cursor.moveToFirst();
    
    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    String filePath = cursor.getString(columnIndex);
    cursor.close();
    
    Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
            
    testimage.setImageBitmap(yourSelectedImage);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    yourSelectedImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byteArray = stream.toByteArray();
    }
    

    Save Image

    DatabaseAdapter dbHelper = new DatabaseAdapter(Profiles.this);
       
           dbHelper.open();
           dbHelper.createUserProfiles( byteArray);
           dbHelper.close();
    

    NOw in DatabaseAdapter.java

    Define

      public static final String U_PIC = "picture";
    

    Then

    private long createUserTableContentValues(long id,byte[] byteImage) {
            ContentValues values = new ContentValues();
            values.put(ID, id);
            values.put(U_PIC, byteImage);
    return database.insert(IMAGE_INSERT, null, values);
    }
    

    I think this might be help you…..

    Other resources:
    http://www.helloandroid.com/tutorials/store-imagesfiles-database

    http://www.coderanch.com/t/507054/Android/Mobile/Storing-image-database

    https://web.archive.org/web/20200718180158/http://www.tutorialforandroid.com/2009/10/how-to-insert-image-data-to-sqlite.html

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

Sidebar

Related Questions

i have tried this code to redirect a php page.but it s not working
I have tried this but it doesn't work: tell application Preview set myfile to
Hello you naughty code animals.. I have tried to get this code to work,
This code is what i have tried to process the query, either delete or
Could anyone please help me convert this code to vb.net, I have tried it
I am trying to enable mod_deflate. I have Apache 2.0+ and tried this code
In this C code i have tried to assign pointer addresses of one variable
I have tryed to run this code in my console: script/plugin install git://github.com/apotonick/cells.git ...but
I have tried this but it does not work (even if I specify .wav
I have this code I been working on but I'm having a hard time

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.