Guest User

Untitled

a guest
Jan 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. Intent sendIntent = new Intent(Intent.ACTION_SEND);
  2. sendIntent.setType("image/jpeg");
  3. sendIntent.putExtra(Intent.EXTRA_STREAM, "IDONTKNOW");
  4. sendIntent.putExtra(Intent.EXTRA_TEXT,
  5. "See my captured picture - wow :)");
  6. startActivity(Intent.createChooser(sendIntent, "share"));
  7.  
  8. File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
  9. File imageFile = new File(path, getCurrentTime()+ ".png");
  10. FileOutputStream fileOutPutStream = new FileOutputStream(imageFile);
  11. bitmap.compress(Bitmap.CompressFormat.PNG, 80, fileOutPutStream);
  12.  
  13. fileOutPutStream.flush();
  14. fileOutPutStream.close();
  15.  
  16. return Uri.parse("file://" + imageFile.getAbsolutePath());
  17.  
  18. private Uri storeImage() {
  19. this.storedImage = null;
  20. this.storeImage = true;
  21. // Wait for the image
  22. while (this.storedImage == null && !this.stop)
  23. try {
  24. Thread.sleep(100);
  25. } catch (InterruptedException e) {
  26. e.printStackTrace();
  27. }
  28. this.storeImage = false;
  29. FileOutputStream fileOutputStream = null;
  30. File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
  31. File file = new File(path, "cwth_" + getCurrentTime()+ ".jpg");
  32. try {
  33. fileOutputStream = new FileOutputStream(file);
  34. } catch (FileNotFoundException e) {
  35. e.printStackTrace();
  36. }
  37. BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
  38. this.storedImage.compress(CompressFormat.JPEG, JPEG_STORE_QUALITY, bos);
  39. try {
  40. bos.flush();
  41. bos.close();
  42. fileOutputStream.flush();
  43. fileOutputStream.close();
  44. } catch (IOException e) {
  45. e.printStackTrace();
  46. }
  47. return Uri.parse("file://" + file.getAbsolutePath());
  48. }
  49.  
  50. Intent shareIntent = new Intent();
  51. shareIntent.setAction(Intent.ACTION_SEND);
  52. shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
  53. shareIntent.setType("image/jpeg");
  54. startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
Add Comment
Please, Sign In to add comment