Skip to content

Instantly share code, notes, and snippets.

@yaronv
Created May 28, 2015 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaronv/fafecc43e685b8932bec to your computer and use it in GitHub Desktop.
Save yaronv/fafecc43e685b8932bec to your computer and use it in GitHub Desktop.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ImageView viewImage = (ImageView) findViewById(R.id.image_placeholder);
ImageView analyzeIcon = (ImageView) findViewById(R.id.analyze_icon);
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
File f = new File(Environment.getExternalStorageDirectory().toString());
for (File temp : f.listFiles()) {
if (temp.getName().equals("temp.jpg")) {
f = temp;
break;
}
}
try {
Bitmap bitmap;
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(), bitmapOptions);
viewImage.setImageBitmap(bitmap);
viewImage.setBackgroundResource(R.drawable.shape_view_border);
analyzeIcon.setVisibility(View.VISIBLE);
} catch (Exception e) {
e.printStackTrace();
}
} else if (requestCode == 2) {
Uri selectedImage = data.getData();
String[] filePath = { MediaStore.Images.Media.DATA };
Cursor c = getContentResolver().query(selectedImage,filePath, null, null, null);
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePath[0]);
String picturePath = c.getString(columnIndex);
c.close();
Bitmap thumbnail = (BitmapFactory.decodeFile(picturePath));
viewImage.setImageBitmap(thumbnail);
analyzeIcon.setVisibility(View.VISIBLE);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment