1

I'm trying to compress my images before it gets uploaded to firebase storage. I am follwing this tutorial on youtube that I found. I followed along as I was told, but when I test everything the app stops and I'm getting this error message saying Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=8478, uid=10163 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission(). I have already added permisson for reading external storage so I'm not sure what this is about. Can someone help me wih this issue thanks.

 //Android manifest

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


    //AllinoneActivity.java

   final ProgressDialog progressDialog = new ProgressDialog(AllInOneActivity.this);
        progressDialog.setTitle("Uploading");
        progressDialog.show();



        if ( filepath==null) {


        Toast.makeText(AllInOneActivity.this, "All Fields required", Toast.LENGTH_LONG).show();
        } else {

        File file=new File(SiliCompressor.with(AllInOneActivity.this).compress(FileUtils.getPath(AllInOneActivity.this,filepath),new File(AllInOneActivity.this.getCacheDir(),"temp")));
        Uri uri=Uri.fromFile(file);

        storageRef.child("images/").child(anstronCoreHelper.getFileNameFromUri(uri)).putFile(filepath).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

        progressDialog.dismiss();
        Toast.makeText(AllInOneActivity.this, "Uploaded successfully", Toast.LENGTH_LONG).show();
        taskSnapshot.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
        String download_url = uri.toString();

        String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
final DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference("images");
final DatabaseReference update = rootRef.child(uid);



        String uploadId=update.push().getKey();











        update.child(uploadId).child("Image").setValue(download_url);



        }
        });
        }
        }).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
        progressDialog.dismiss();
        Toast.makeText(AllInOneActivity.this, "Failed to upload", Toast.LENGTH_LONG).show();

        }
        }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
        double progress = (100.0 * taskSnapshot.getBytesTransferred() / taskSnapshot
        .getTotalByteCount());
        progressDialog.setMessage("Uploaded " + (int) progress + "%");

        }
        });


        }
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
steph
  • 81
  • 1
  • 7
  • Not sure about the issue, but are you running an emulator or via a usb debugger on your phone? Sometimes an app will crash if the device you are launching to does not have that feature. I tried using ble on a phone without ble capabilities and would get a similar error. – Thomas Morris May 11 '20 at 07:04
  • @Thomas Morris im using a real device – steph May 11 '20 at 16:09
  • 1
    Have you checked the permissions and run using the inbuilt debugger. As in where does it crash? On startup build or running a certain api? – Thomas Morris May 11 '20 at 16:47
  • @ThomasMorris the problem was that the phone did not have permission for storage so I enable it one the device and it works. So I have to write some code to ask for permission for storage. Now that I ran everything I noticed that image isn’t really compressing. Is there like another library you may know of? – steph May 11 '20 at 18:25
  • 1
    @ThomasMorris I found my answer. here https://stackoverflow.com/a/43885809/13401380 – steph May 12 '20 at 02:30

0 Answers0