Android getting thumbnail Uri after getting picture from the Camera - android

I do not want to use any bitmap resizing code if I can help it.
I have a method to get a MINI thumbnail uri when I get pictures from the Gallery but when I try to do the same with the Camera it does not work:
Here are the methods:
private Uri getParsedUri(Uri selectedImageUri) {
Uri parsed = null;
try {
String uri = getThumbnailPath(selectedImageUri);
if (uri != null) {
Timber.d("Thumb uri found %s", uri);
File file = new File(uri);
parsed = Uri.fromFile(file);
Timber.d("thumb uri parsed : %s", parsed);
} else {
Timber.d("Thumb uri not found, using : %s", selectedImageUri);
}
} catch (Exception e){
Timber.e(e, "Error getting mini uri");
}
return parsed;
}
private String getThumbnailPath(Uri uri) {
String[] projection = { MediaStore.Images.Media._ID };
String result = null;
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if (cursor != null && cursor.getCount() > 0) {
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
cursor.moveToFirst();
long imageId = cursor.getLong(column_index);
cursor.close();
Cursor cursor2 = MediaStore.Images.Thumbnails.queryMiniThumbnail(
getContentResolver(), imageId,
MediaStore.Images.Thumbnails.MINI_KIND,
null);
if (cursor2 != null && cursor2.getCount() > 0) {
cursor2.moveToFirst();
result = cursor2.getString(cursor2.getColumnIndexOrThrow(MediaStore.Images.Thumbnails
.DATA));
cursor2.close();
}
}
return result; //always null for pictures from the Camera
}
Here is how I provide the uri extra for the Camera app:
private void onTakePhotoFromCameraClick() {
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// takePicUri = Uri.fromFile(getTempFile(ProductNewActivity.this));
takePicUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new ContentValues());
intent.putExtra(MediaStore.EXTRA_OUTPUT,
takePicUri);
startActivityForResult(intent, OPTION_TAKE_PHOTO_FROM_CAMERA);
}
private File getTempFile(Context context) {
final File path = new File(Environment.getExternalStorageDirectory(),
context.getPackageName());
if (!path.exists()) {
path.mkdir();
}
long millis = new Date().getTime();
String name_file = String.valueOf(millis);
File tempImageFile = new File(path, "MyImage_" + name_file + ".tmp");
return tempImageFile;
}
both of the methods of getting the Uri (either using content resolver or creating my custom Uri, do not work and I am never able to get a thumbnail. Is there a way to indicate the system to generate a thumbnail? Is the thumbnail always generated?.
Edit: I think I did not explain clearly. I need 2 Uri: one for big image and one for a thumbnail. I do not need the bitmaps. I am using Universal Image Loader to display the images so I do not need the small bitmap. I generate the Uri for the big image myself but I would like to find a way for Android to generate the thumbnail since it already does it for pictures of the gallery.

I have this piece of code which may helpful for you,Let me tell you this code will invoke camera and take a picture stored in external directory with full resolution and you can refer this path any time.
final int TAKE_PHOTO_REQ = 100;
String file_path = Environment.getExternalStorageDirectory()
+ "/recent.jpg";
file = new File(file_path);
public void takePic(){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PHOTO_REQUEST_FRAG);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case TAKE_PHOTO_REQ: {
if (resultCode == TakePicture.RESULT_OK && data != null) {
Bitmap myBmp = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(myBmp);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
// you can create a new file name "recent.jpg" in sdcard folder.
File f = new File(file_path);
try {
f.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// write the bytes in file
FileOutputStream fo = null;
try {
fo = new FileOutputStream(f);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
fo.write(bytes.toByteArray());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// remember close de FileOutput
try {
fo.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.e("take-img", "Image Saved to sd card...");
break;
}
}
}
}
Hope this will help you.

If you are interested only in a thumbnail then start the intent as follows:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_THUMB );
Then in OnActivityResult you can extract the thumb from the intent like:
Bundle extras = data.getExtras();
Bitmap bitmap = (Bitmap) extras.get("data");
imageView1.setImageBitmap(bitmap);

Related

Android get path of latest taken photo

I'm launching the camera from my app to take a photo. It also becomes available in the gallery.
The common issue with this, is how to know the path of the photo. The proposed solutions are:
save the path yourself, and send it over using EXTRA_OUTPUT
take the path from the last taken photo in the gallery.
Solution 1 isn't reliable.
I'm trying to make solution 2 work, with this code:
public static String getTakenPhotoPath(Context context) {
try {
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, null, null, null);
int column_index_data = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToLast();
return cursor.getString(column_index_data);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
This doesn't return the path of the latest photo; it returns the previous one. Before asking for the path of the latest photo, I'm doing this:
private void addToGallery(Uri urlType, String path) {
if (!Strings.isNullOrEmpty(path)) {
ContentValues values = new ContentValues();
// Add the date meta data to ensure the image is added at the front of the gallery
values.put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis());
values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
values.put(MediaStore.MediaColumns.DATA, path);
getContentResolver().insert(urlType, values);
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(new File(path));
mediaScanIntent.setData(contentUri);
sendBroadcast(mediaScanIntent);
}
}
You can it do like this: When you are opening the camera, you can pass your own preferred location for future captured image like this in given code. And in onActivityResult you can directly use that image path for your use.
File image ;
Intent photoCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MyImages");
imagesFolder.mkdirs(); // <----
image = new File(imagesFolder, getFileName());
Uri uriSavedImage = Uri.fromFile(image);
photoCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(photoCaptureIntent, PICK_FROM_CAMERA);
private String getFileName() {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
Date now = new Date();
String fileName = formatter.format(now) + ".jpg";
return fileName;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
setResult(resultCode, data);
switch (requestCode) {
case PICK_FROM_CAMERA:
try {
if (resultCode != RESULT_CANCELED) {
Intent upload = new Intent(EditProfile.this, ImageCropingFucAtivity.class);
prefs.edit().putBoolean("FromCamera", true).commit();
upload.putExtra(CropImage.IMAGE_PATH, image.toString());
upload.putExtra(CropImage.SCALE, true);
upload.putExtra(CropImage.ASPECT_X, 2);
upload.putExtra(CropImage.ASPECT_Y, 2);
startActivity(upload);
imageSelected = true;
finish();
}
} catch (Exception e) {
e.printStackTrace();
}
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}

Not able to copy image using ACTION_GET_CONTENT

I am trying to copy image using below code:
Intent intentImage = new Intent();
intentImage.setType("image/*");
intentImage.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intentImage, 10);
With this i am able to open all image content.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 10) {
if (resultCode != RESULT_OK) return;
Uri selectedImageUri = data.getData();
try {
String selectedImagePath1 = getPath(selectedImageUri);
File file = new File(selectedImagePath1);
String fna = file.getName();
String pna = file.getParent();
File fileImage = new File(pna, fna);
copyFileImage(fileImage, data.getData());
} catch (Exception e) {
}
}
}
private void copyFileImage(File src, Uri destUri) {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(src));
bos = new BufferedOutputStream(getContentResolver().openOutputStream(destUri));
byte[] buf = new byte[1024];
bis.read(buf);
do {
bos.write(buf);
} while (bis.read(buf) != -1);
} catch (NullPointerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bis != null) bis.close();
if (bos != null) bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Now i am successfully get path and name of the image .
Now when i run the above code then it gives me error of requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission().
so i have put the permission in manifest :
i have also defined the permission for read and write internal/external storage.
But still i am getting this error.
How can i copy image ?
Select picture using below code
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), 1);
this will open gallery, after selecting pic you will get selected pic uri in below code
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch(requestCode) {
case 1:
if(resultCode == RESULT_OK)
{
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
File sel = new File(selectedImagePath);
Bitmap bitmap = BitmapFactory.decodeFile(sel.getAbsolutePath());
imageView1.setImageBitmap(bitmap);
Bitmap resized = Bitmap.createScaledBitmap(bitmap, 600,370, true);
ByteArrayOutputStream blob = new ByteArrayOutputStream();
resized.compress(Bitmap.CompressFormat.JPEG, 100, blob);
String StrBase64 = Base64.encodeToString(blob.toByteArray(), Base64.DEFAULT);
imageView1.setImageBitmap(resized);
// Toast.makeText(getApplicationContext(), ""+selectedImagePath, Toast.LENGTH_LONG).show();
}
break;
}
}
public String getPath(Uri uri) {
// just some safety built in
if( uri == null ) {
// TODO perform some logging or show user feedback
return null;
}
// try to retrieve the image from the media store first
// this will only work for images selected from gallery
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if( cursor != null ){
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
// this is our fallback here
return uri.getPath();
}
add permission in manifest
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
this way you will get selected image in Base64 to string
Try this code-
Image will copy in SaveImage folder in sd card
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch(requestCode) {
case 1:
if(resultCode == RESULT_OK)
{
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
File sel = new File(selectedImagePath);
Bitmap bitmap = BitmapFactory.decodeFile(sel.getAbsolutePath());
imageView1.setImageBitmap(bitmap);
SaveImage(bitmap);
}
break;
}
}
private void SaveImage(Bitmap finalBitmap) {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/SaveImage");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}

how to show image in image view

I am working on android custom camera application when i click on gallery view it show mobile default gallery and show photos that i clicked but i want when i click on gallery then clicked image show in my custom view how can i implement
public void clickedGallery(View view) {
if (MyDebug.LOG)
Log.d(TAG, "clickedGallery");
//Intent intent = new Intent(Intent.ACTION_VIEW, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Uri uri = null;
Media media = getLatestMedia();
if (media != null) {
uri = media.uri;
}
if (uri != null) {
// check uri exists
if (MyDebug.LOG)
Log.d(TAG, "found most recent uri: " + uri);
try {
ContentResolver cr = getContentResolver();
ParcelFileDescriptor pfd = cr.openFileDescriptor(uri, "r");
if (pfd == null) {
if (MyDebug.LOG)
Log.d(TAG, "uri no longer exists (1): " + uri);
uri = null;
}
pfd.close();
} catch (IOException e) {
if (MyDebug.LOG)
Log.d(TAG, "uri no longer exists (2): " + uri);
uri = null;
}
}
if (uri == null) {
uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
}
if (!is_test) {
// don't do if testing, as unclear how to exit activity to finish test (for testGallery())
if (MyDebug.LOG)
Log.d(TAG, "launch uri:" + uri);
final String REVIEW_ACTION = "com.android.camera.action.REVIEW";
try {
// REVIEW_ACTION means we can view video files without autoplaying
Intent intent = new Intent(REVIEW_ACTION, uri);
this.startActivity(intent);
} catch (ActivityNotFoundException e) {
if (MyDebug.LOG)
Log.d(TAG, "REVIEW_ACTION intent didn't work, try ACTION_VIEW");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// from http://stackoverflow.com/questions/11073832/no-activity-found-to-handle-intent - needed to fix crash if no gallery app installed
//Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("blah")); // test
if (intent.resolveActivity(getPackageManager()) != null) {
this.startActivity(intent);
} else {
preview.showToast(null, R.string.no_gallery_app);
}
}
}
}
Here is the complete code you can modify the requestCode to whatever you would have declared in your code and you can either pass the Uri or the actual location of the file in the next activity.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_CANCELED) {
if (requestCode == SELECT_FILE && (data != null)) {
Uri selectedImageUri = data.getData();
String[] projection = {MediaStore.MediaColumns.DATA};
Cursor cursor = getContentResolver().query(selectedImageUri, projection, null, null,
null);
assert cursor != null;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
cursor.moveToFirst();
String selectedImagePath = cursor.getString(column_index);
if(selectedImagePath == null) {
selectedImagePath = getActualPathFromUri(selectedImageUri);
}
cursor.close();
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
private String getActualPathFromUri(Uri selectedImageUri) {
Bitmap bitmap = null;
try {
bitmap = getBitmapFromUri(selectedImageUri);
} catch (IOException e) {
e.printStackTrace();
}
if(bitmap == null) {
return null;
}
File imageFileFolder = new File(getCacheDir(),"appName");
if( !imageFileFolder.exists() ){
imageFileFolder.mkdir();
}
FileOutputStream out = null;
File imageFileName = new File(imageFileFolder, "appName-" + System.currentTimeMillis() + ".jpg");
try {
out = new FileOutputStream(imageFileName);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (IOException e) {
Log.i("Exception", e.getMessage());
} finally {
if(out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return imageFileName.getAbsolutePath();
}
private Bitmap getBitmapFromUri(Uri uri) throws IOException {
ParcelFileDescriptor parcelFileDescriptor =
getContentResolver().openFileDescriptor(uri, "r");
assert parcelFileDescriptor != null;
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
parcelFileDescriptor.close();
return image;
}
When you back from camera after you take picture or back from gallery your onActivityResult method will call. So override your onActivityResult like the following
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
//Read your image here and set in your imageView
}
}
Edit:
Set image to image view
Inside of the onActivityResult
if(data.getData()==null){
bitmap = (Bitmap)data.getExtras().get("data");
}else{
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
}
yourImageView.setImageBitmap(img);

Android: Saving image from gallery and then loading into imageview

I have an onclick that will allow a user to select a file from gallery like so:
case R.id.ColourCustom:
customBorderChange();
break;
private void customBorderChange() {
final ImageView QPBackground = (ImageView) findViewById(R.id.QPBackground);
menuHandler.removeCallbacks(menuTimer);
menuHandler.postDelayed(menuTimer, 5000);
bgHandler.removeCallbacks(runnableBG);
bgHandler.postDelayed(runnableBG, 2000);
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, GALLERY_REQUEST);
File file = getFileStreamPath("QuickPlayBG.png");
if (file.exists()) {
QPBackground.setImageBitmap(getThumbnail("QuickPlayBG.png"));
} else {
String uri21 = "#drawable/bg_green";
int imageResource21 = getResources().getIdentifier(uri21, null, getPackageName());
QPBackground.setBackgroundResource(imageResource21);
}
}
This sends you here:
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
Uri selectedImageUri;
if (requestCode == GALLERY_REQUEST && resultCode == RESULT_OK && null !=
data) {
selectedImageUri = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImageUri,
filePathColumn, null, null, null);
cursor.moveToFirst();
cursor.close();
}
try {
Bundle extras = data.getExtras();
Bitmap photo = extras.getParcelable("data");
saveBGFile(photo);
} catch (Exception e) {
String errorMessage = "Make your mind up mate!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
try {
saveQPConfig();
} catch (IOException e) {
String errorMessage = "Saving failed";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
Which saves the file, using saveBGFile:
public void saveBGFile(Bitmap image) {
FileOutputStream out = null;
String filename = "QuickPlayBG.png";
try {
out = new FileOutputStream(filename);
image.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
The issue is with this line only:
QPBackground.setImageBitmap(getThumbnail("QuickPlayBG.png"));
It doesn't load anything. If I change "QuickPlayBG.png" to another filename that I am using in another part of my app, it loads fine. Both files are created using the same method. I verified that "QuickPlayBG.png" exists.
Compiler gives me the following hint:
E/﹕ ReadStreamToBuffer : Qmage Stream read error!! required length 12 bytes, but red 0 bytes
E/﹕ isQmage : input SkStreamRewindable length is less than Qmage minimum size : 0
I think it has to do with the way I am saving the image, but I cannot see the fault myself. What could be the problem, that it is not loading the image?
Edit:
Here is the getThumbnail method I am using (works for another filename):
public Bitmap getThumbnail(String filename) {
final Context context = this;
String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath();
Bitmap thumbnail = null;
if (thumbnail == null) {
try {
File filePath = context.getFileStreamPath(filename);
FileInputStream fi = new FileInputStream(filePath);
thumbnail = BitmapFactory.decodeStream(fi);
} catch (Exception ex) {
Log.e("getThumbnail() !exist", ex.getMessage());
}
}
return thumbnail;
}
Use this short and sweet code for this. use intent of gallery.
1.declaire variable.
private static int RESULT_IMG = 1;
String imgString;
2.call intent of gallery on onclick of button.
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
3.onActivityResult to your code.
#Override
protected void onActivityResult(int requestCode, int responseCode, Intent data) {
super.onActivityResult(requestCode, responseCode, data);
try {
if (requestCode == RESULT_IMG && responseCode == RESULT_OK
&& null != data) {
Uri pickedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(pickedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgString = cursor.getString(columnIndex);
cursor.close();
//set bitmap to your imageview
ImageView imgView = (ImageView) findViewById(R.id.imgView);
imgView.setImageBitmap(BitmapFactory.decodeFile(imgString));
} else {
Toast.makeText(this, "please select picture",Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "error message", Toast.LENGTH_LONG)
.show();
}
}

Android: Browse and upload a PDF or word file in application from the device

I am creating an android mobile application in which user can upload his/her resume and which can be then sent to the server.
Resume can be in pdf form or word form.
How to browse for the pdf and word files, which type should be given to browse these files? like for images we have image.
Thanks.
Use this function:
private void getDocument()
{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/msword,application/pdf");
intent.addCategory(Intent.CATEGORY_OPENABLE);
// Only the system receives the ACTION_OPEN_DOCUMENT, so no need to test.
startActivityForResult(intent, REQUEST_CODE_DOC);
}
#Override
protected void onActivityResult(int req, int result, Intent data)
{
// TODO Auto-generated method stub
super.onActivityResult(req, result, data);
if (result == RESULT_OK)
{
Uri fileuri = data.getData();
docFilePath = getFileNameByUri(this, fileuri);
}
}
// get file path
private String getFileNameByUri(Context context, Uri uri)
{
String filepath = "";//default fileName
//Uri filePathUri = uri;
File file;
if (uri.getScheme().toString().compareTo("content") == 0)
{
Cursor cursor = context.getContentResolver().query(uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA, MediaStore.Images.Media.ORIENTATION }, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String mImagePath = cursor.getString(column_index);
cursor.close();
filepath = mImagePath;
}
else
if (uri.getScheme().compareTo("file") == 0)
{
try
{
file = new File(new URI(uri.toString()));
if (file.exists())
filepath = file.getAbsolutePath();
}
catch (URISyntaxException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
filepath = uri.getPath();
}
return filepath;
}
I hope this will help you.

Categories

Resources