Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
  2.  
  3.  
  4. try {
  5. String file_path = "";
  6. super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
  7. if (resultCode == RESULT_OK) {
  8. if (requestCode == CAMERA_REQUEST) {
  9. Bitmap thumbnail = (Bitmap) imageReturnedIntent.getExtras().get("data");
  10. ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  11. thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
  12. File destination = new File(Environment.getExternalStorageDirectory(),
  13. System.currentTimeMillis() + ".jpg");
  14. file_path = destination.getPath();
  15. editor.putString("image_path", file_path);
  16. editor.commit();
  17.  
  18. FileOutputStream fo;
  19. try {
  20. destination.createNewFile();
  21. fo = new FileOutputStream(destination);
  22. fo.write(bytes.toByteArray());
  23. fo.close();
  24. Picasso.with(Sell_Main.this).load(destination).into(imgone);
  25. } catch (FileNotFoundException e) {
  26. Toast.makeText(Sell_Main.this, e.getMessage(), Toast.LENGTH_SHORT).show();
  27. } catch (IOException e) {
  28. Toast.makeText(Sell_Main.this, e.getMessage(), Toast.LENGTH_SHORT).show();
  29. }
  30. }
  31. }
  32. } catch (Exception e) {
  33. Toast.makeText(Sell_Main.this, e.getMessage(), Toast.LENGTH_SHORT).show();
  34. }
  35. }
  36.  
  37.  
  38. public void Image_Picker_Dialog()
  39. {
  40. AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
  41. myAlertDialog.setMessage("Select Picture Mode");
  42.  
  43. myAlertDialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener()
  44. {
  45. public void onClick(DialogInterface arg0, int arg1)
  46. {
  47.  
  48. Intent pickPhoto = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  49. pickPhoto.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
  50. startActivityForResult(pickPhoto , 1);
  51.  
  52. }
  53. });
  54.  
  55. myAlertDialog.setNegativeButton("Camera", new DialogInterface.OnClickListener()
  56. {
  57. public void onClick(DialogInterface arg0, int arg1)
  58. {
  59. Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  60. takePicture.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
  61. startActivityForResult(takePicture, 0);
  62. }
  63. });
  64. myAlertDialog.show();
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement