I tried and tested the work on the Galaxy S3 phone. Thank TGMCians for your help.
public class MainActivity extends Activity { private static final int PICK_IMAGE = 0; private static final int PICK_IMAGE_FROM_GALLERY = 1; private Button mBtnCamera, mBtnGallery, mBtnCancel; private ImageView mImageView; private Uri mURI; private String mPhotoPath; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mImageView = (ImageView) findViewById(R.id.imgDisplayImage); mBtnCamera = (Button) findViewById(R.id.btnPhotoCamera); mBtnGallery = (Button) findViewById(R.id.btnPhotoGallery); mBtnCancel = (Button) findViewById(R.id.btnCancel); mBtnCamera.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent camera = new Intent(); camera.setAction(MediaStore.ACTION_IMAGE_CAPTURE); camera.putExtra("crop", "true"); File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); mURI = Uri.fromFile(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "myFile.jpg")); camera.putExtra(MediaStore.EXTRA_OUTPUT, mURI); startActivityForResult(camera, PICK_IMAGE); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if (requestCode == PICK_IMAGE) { Cursor cursor = getContentResolver().query( Media.EXTERNAL_CONTENT_URI, new String[] { Media.DATA, Media.DATE_ADDED, MediaStore.Images.ImageColumns.ORIENTATION }, Media.DATE_ADDED, null, "date_added ASC" ); if (cursor != null && cursor.moveToFirst()) { do { mURI = Uri.parse(cursor.getString(cursor.getColumnIndex(Media.DATA))); mPhotoPath = mURI.toString(); } while (cursor.moveToNext()); cursor.close(); } if (data != null) { if (data.hasExtra("data")) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); mImageView.setImageBitmap(thumbnail); } else { System.out.println("Intent bundle does not have the 'data' Extra"); int width = mImageView.getWidth(); int height = mImageView.getHeight(); BitmapFactory.Options factoryOptions = new BitmapFactory.Options(); factoryOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile( mPhotoPath, factoryOptions); int imageWidth = factoryOptions.outWidth; int imageHeight = factoryOptions.outHeight;
source share