@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_product); // Initialization of the variables inputProductName = (EditText) findViewById(R.id.inputProductName); inputProductQuantity = (EditText) findViewById(R.id.inputProductQuantity); inputProductPrice = (EditText) findViewById(R.id.inputProductPrice); inputProductEmail = (EditText) findViewById(R.id.inputEmail); imageProduct = (ImageView) findViewById(R.id.imageNewProduct); productUri = ""; setupToolbar(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK && null != imageReturnedIntent) { if (resultCode == RESULT_OK) { Uri selectedImage = imageReturnedIntent.getData(); productUri = selectedImage.toString(); InputStream imageStream = null; try { imageStream = getContentResolver().openInputStream(selectedImage); } catch (FileNotFoundException e) { e.printStackTrace(); } Bitmap imageResult = BitmapFactory.decodeStream(imageStream); imageProduct.setImageBitmap(imageResult); } } }