I am trying to develop an android app in which there is an option to upload image from phone memory and then it will display in a list View with some heading given by user.
I have created layout of it but I don't know how to implement this concept.
I used one EditText and a Button for uploading file in LinearLayout and use ListView in another activity to display images
Asked
Active
Viewed 561 times
0
P Sharma
- 184
- 9
-
post what you have tried? else you get automatically downvote.. – Ranjithkumar Apr 30 '15 at 13:37
-
I'm wondering if you even looked for an answer before posting this... https://stackoverflow.com/questions/9357668/how-to-store-image-in-sqlite-database – nasch Apr 30 '15 at 13:53
-
I used one EditText and a Button for uploading file in LinearLayout and use ListView in another activity to display images. @ranjith – P Sharma Apr 30 '15 at 15:29
-
@PravalSharma edit your question..I am also get many downvotes in my qtn by this mistake. – Ranjithkumar Apr 30 '15 at 15:33
-
1okk i will explain my layout in ques @ranjith – P Sharma Apr 30 '15 at 16:36
1 Answers
1
First you have to get the image from the Phone memory such as `
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
Bitmap mBitmap = null;
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
Uri chosenImageUri = data.getData();
mBitmap = Media.getBitmap(this.getContentResolver(), chosenImageUri);
}
}
` You will get the image in the form of Bitmap image. Convert this Bitmap image into the ByteArray[]:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mBitmap .compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Then take a column in Database with blob data type and then insert this byte array in that column;
db.execSQL("create table Images(id integer, imageData blob);");
for insert
ContentValues values = new ContentValues();
values.put("id", imageIdValue);
values.put("imageData ", byteArray);
database.insert("Image", null, values);
I hope this will help you.
Bhagwat K
- 2,859
- 2
- 22
- 31