Guest User

Untitled

a guest
Jun 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. storageRef = FirebaseStorage.getInstance().getReference().child("/folder/photo.jpg");
  2.  
  3. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  4. if (intent.resolveActivity(getPackageManager()) != null) {
  5. startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
  6. }
  7.  
  8. @Override
  9. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  10. if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
  11. Bundle extras = data.getExtras();
  12. Bitmap imageBitmap = (Bitmap) extras.get("data");
  13. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  14. imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
  15. byte[] data = baos.toByteArray();
  16. ByteArrayInputStream bs = new ByteArrayInputStream(data);
  17. UploadTask uploadTask = storageRef.putStream(bs);
  18. uploadTask.addOnSuccessListener(taskSnapshot -> {
  19.  
  20. new L().info(storageRef.getDownloadUrl()+"");
  21. new AlertUtil().showCustomAlert(this,"done");
  22. });
  23. }
  24. }
  25.  
  26. com.google.android.gms.tasks.zzu@64b8bf6
  27.  
  28. Uri selectedImageUri = data.getData();
  29. StorageReference photoRef = mSRreference.child(selectedImageUri.toString());
  30. photoRef.putFile(selectedImageUri).addOnSuccessListener(new
  31. OnSuccessListener<UploadTask.TaskSnapshot>() {
  32. @Override
  33. public void onSuccess(UploadTask.TaskSnapshot taskSnapshot){
  34. // your download uri - taskSnapshot.getDownloadUrl()
  35. }
  36.  
  37. }).addOnFailureListener(new OnFailureListener() {
  38. @Override
  39. public void onFailure(@NonNull Exception e) {
  40. }
  41. });
  42.  
  43. UploadTask uploadTask = storageRef.putStream(bs);
  44. uploadTask.addOnSuccessListener(taskSnapshot -> {
  45. storageRef.getDownloadUrl().addOnCompleteListener(task ->
  46. new L().info("url" + task.getResult()));
  47. });
  48.  
  49. compileOptions {
  50. targetCompatibility 1.8
  51. sourceCompatibility 1.8
  52. }
Add Comment
Please, Sign In to add comment