I want to store some images on a database, recover them later and show them on a custom ListView
. How can I do that?
Here's what I've done so far:
//here, we are making a folder named picFolder to store pics taken by the camera using this application
dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/picFolder/";
File newdir = new File(dir);
if(!newdir.exists()){
newdir.mkdirs();
}
//Switch cases are
case R.id.btnPhotoGallary2:
Intent gallaryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(gallaryIntent , TAKE_GALLARY_CODE);//one can be replced with any action code
break;
case R.id.btnPhotoCamera1:
count++;
String file = dir+count+".jpg";
File newfile = new File(file);
try {
newfile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
capturedPhotoUri = Uri.fromFile(newfile);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedPhotoUri);
startActivityForResult(cameraIntent, TAKE_CAMERA_CODE);
break;
// Set Photo to Button/ImageView
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 0://Captured photo from Camera
if(resultCode == RESULT_OK){
String pathNamePhoto = capturedPhotoUri.getPath().toString();
System.out.println("Photo Path Is :"+pathNamePhoto);
d = BitmapDrawable.createFromPath(pathNamePhoto);
ivProfile.setImageDrawable(d);
Log.d("CameraDemo", "Pic saved");
Log.v("CapturedPhoto PATH ==>> ",pathNamePhoto);
pd.setProfImagepath(pathNamePhoto);
}
dialog.dismiss();
break;
case 1://Select Image from Gallery
if(resultCode == RESULT_OK){
Uri selImageUri = data.getData();
String pathNameImage = getPath(selImageUri);
System.out.println("Image Path Is :"+pathNameImage);
ivProfile.setImageURI(selImageUri);
Log.d("GallaryDemo", "Get Pic ");
Log.v("IMAGE PATH ==>> ",pathNameImage);
pd.setProfImagepath(pathNameImage);
}
dialog.dismiss();
break;
}
}
//Get Real Path Of Image
@SuppressWarnings("deprecation")
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);
}