Guest User

Untitled

a guest
Jun 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. mBotFoto.setOnClickListener(new View.OnClickListener() {
  2. @Override
  3. public void onClick(View view) {
  4. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  5. try {
  6. mFileTemp = new File(getActivity().getCacheDir(), "temp_photo2.jpg");
  7. uri = FileProvider.getUriForFile(getContext(), "br.com.legalestudioapp.legalmototaxiagente.fileprovider2", mFileTemp);
  8. intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
  9. intent.putExtra("return-data", true);
  10. intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  11. startActivityForResult(intent, IMAGEM_CAMERA);
  12. } catch (ActivityNotFoundException e) {
  13. Toast.makeText(getContext(), "Não foi possível abrir a câmera!", Toast.LENGTH_LONG).show();
  14. }
  15. }
  16. });
  17.  
  18.  
  19. @Override
  20. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  21. if (resultCode == Activity.RESULT_OK) {
  22. if (requestCode == IMAGEM_CAMERA) {
  23. if (mFileTemp == null) {
  24. Toast.makeText(getContext(), "nao carregou foto da camera", Toast.LENGTH_LONG).show();
  25. return;
  26. }
  27.  
  28. //Uri uri = FileProvider.getUriForFile(getActivity().getApplicationContext(), "br.com.legalestudioapp.legalmototaxiagente.fileprovider", mFileTemp);
  29. // Intent i=new Intent(Intent.ACTION_VIEW, FileProvider.getUriForFile(this, AUTHORITY, mFileTemp));
  30. try {
  31. Intent cropIntent = new Intent("com.android.camera.action.CROP");
  32. cropIntent.setDataAndType(uri, "image/*");
  33. cropIntent.putExtra("crop", "true");
  34. cropIntent.putExtra("aspectX", 1);
  35. cropIntent.putExtra("aspectY", 1);
  36. cropIntent.putExtra("outputX", 640);
  37. cropIntent.putExtra("outputY", 640);
  38. cropIntent.putExtra("return-data", true);
  39. cropIntent.putExtra("noFaceDetection", true);
  40. cropIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  41. startActivityForResult(cropIntent, PIC_CROP);
  42. } catch (Exception e) {
  43. Toast.makeText(getContext(), "não foi possível editar", Toast.LENGTH_LONG).show();
  44. Bundle extras = data.getExtras();
  45. //get the cropped bitmap
  46. Bitmap foto = extras.getParcelable("data");
  47. mFotoC.setImageBitmap(foto);
  48. mFoto = foto;
  49. Long tsLong = System.currentTimeMillis() / 1000;
  50. timestamp = tsLong.toString();
  51. }
  52.  
  53.  
  54. }
  55. if (requestCode == PIC_CROP) {
  56. Bundle extras = data.getExtras();
  57. //get the cropped bitmap
  58. Bitmap foto = extras.getParcelable("data");
  59. mFotoC.setImageBitmap(foto);
  60. mFoto = foto;
  61. Long tsLong = System.currentTimeMillis() / 1000;
  62. timestamp = tsLong.toString();
  63. }
  64. }
  65. }
Add Comment
Please, Sign In to add comment