Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
88 views
in Technique[技术] by (71.8m points)

android studio - ERROR_UNKNOWN downloading file from Firebase Storage

Im trying to download a file *.Apk from the storage and install when is completed. i revised the rules from storage and the uses.

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read : if request.auth.uid != null;
    }
  }
}

on rules monitor all operations are accepted but the file can't be donwloaded

fragment of donwload code is:

public void downloadUpdate() {
    StorageReference gsReference = FirebaseStorage.getInstance("filename.apk");
    final String rutadestino = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
    final String nombrearchivo = "LeaderBoard-Upd.apk";
    final Uri archivodestino = Uri.parse("file://" + rutadestino+nombrearchivo);
    File localFile = new File(rutadestino+nombrearchivo);
    if (localFile.exists()) {
        localFile.delete();
    }

    gsReference.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
             //Local temp file has been created
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                Uri contentUri = FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", new File(rutadestino+nombrearchivo));
                Intent install = new Intent(Intent.ACTION_VIEW);
                install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                install.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                install.setData(contentUri);
                startActivity(install);
                //unregisterReceiver(this);
                finish();
            } else {
                Intent install = new Intent(Intent.ACTION_VIEW);
                install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                install.setDataAndType(archivodestino,
                        "application/vnd.android.package-archive");
                startActivity(install);
                //unregisterReceiver(this);
                finish();
            }
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Handle any errors
            int errorCode = ((StorageException) exception).getErrorCode();
            String errorMessage = exception.getMessage();
            Emergente.ErrorCode(1,getApplicationContext());
        }
    });
}

i received errorcode "13000" errorMessage "An unknown error occurred, please check the HTTP result code and inner exception for server response." cause "open failed: EACCES (Permission denied)"

Maybe another code fragment is wrong, but in this momment im stucked on the OnFailureListener

question from:https://stackoverflow.com/questions/65672085/error-unknown-downloading-file-from-firebase-storage

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem is on the app permissions, when app tries to download files and write it on a wrong directory/file without the required permission it will trow the "ERROR_UNKNOWN" message.

The solution is create the file on the same app directory, when doing so the permission is not required unles the API <= 18 then the permission will be necessary.

Solution:

File localFile = new File(getExternalFilesDir(null), "file.apk");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...