Reputation: 187
//below
In my application i have a button select image from sdcard and on clicking it, I want to explore all the images then user will select any image after this the selected image file will be uploaded to server.
And also i have an another button from camera on clicking it, first i want to take a snapshot, and then uploaded to server, please tell me any way by example??
Upvotes: 1
Views: 1486
Reputation: 187
it is very easy to browse the image by deafult gallery using the intent so by using the intent you can easily choose the image from sd card and from your file browser.
Upvotes: 0
Reputation: 4816
Here is the code I use to query the phone's MediaStore and return a cursor object containing all images. After that you may upload them to your server, but I suggest you take care of this first part in an AsyncTask.
class LoadImagesFromSDCard extends AsyncTask<Object, LoadedImage, Object> {
//Load images from SDCARD and display
@Override
protected Object doInBackground(Object... params) {
//setProgressBarIndeterminateVisibility(true);
Bitmap bitmap = null;
Bitmap newBitmap = null;
Uri uri = null;
// Set up an array of the Thumbnail Image ID column we want
String[] projection = {MediaStore.Images.Thumbnails._ID};
// Create the cursor pointing to the SDCard
Cursor cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,
null);
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
int size = cursor.getCount();
// If size is 0, there are no images on the SD Card.
if (size == 0) {
//No Images available, post some message to the user
}
int imageID = 0;
for (int i = 0; i < size; i++) {
cursor.moveToPosition(i);
imageID = cursor.getInt(columnIndex);
uri = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID);
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
if (bitmap != null) {
newBitmap = Bitmap.createScaledBitmap(bitmap, 70, 70, true);
bitmap.recycle();
if (newBitmap != null) {
publishProgress(new LoadedImage(newBitmap));
}
}
} catch (IOException e) {
//Error fetching image, try to recover
}
}
cursor.close();
return null;
}
Upvotes: 1