These solutions really did not solve my problem.
what solved my problem was the following lines:
in the application module
implementation 'com.google.firebase:firebase-database:15.0.0' implementation 'com.google.firebase:firebase-storage:15.0.0' implementation 'com.google.firebase:firebase-auth:15.0.0'
and this code to download and get the download link
private void uploadImageToFirebase(Bitmap bmp) { try { String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/news"; File dir = new File(file_path); if (!dir.exists()) dir.mkdirs(); File file = new File(dir, "sketchpad" + "_" + ".png"); FileOutputStream fOut = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 100, fOut); fOut.flush(); fOut.close(); Log.i("SECONDACTIVITY", "ADDED SUCCESSFULLY"); Uri file2 = Uri.fromFile(file); //Now Upload final StorageReference storageRef = FirebaseStorage.getInstance().getReference(); StorageReference riversRef = storageRef.child(file.getName()); UploadTask uploadTask; uploadTask = riversRef.putFile(file2); progressDialog.show(); progressDialog.setCancelable(false); uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() { @Override public void onProgress(UploadTask.TaskSnapshot taskSnapshot) { double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount(); progressDialog.incrementProgressBy((int) progress); } }); uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { progressDialog.dismiss(); Uri DownloadLink = taskSnapshot.getDownloadUrl(); String imgUrl = DownloadLink.toString(); FirebaseDatabase.getInstance().getReference().child("image_link").setValue(imgUrl); } }); uploadTask.addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { progressDialog.dismiss(); } }); } catch (IOException e) { e.printStackTrace(); } }
source share