Firebase存储未显示数据

时间:2016-12-31 09:17:41

标签: android firebase firebase-storage

我正在使用Firebase存储来保存图片/视频/和音频。我有两个API密钥:调试和发布。当我在手机上运行应用程序时,一切正常。但是,当我生成发布版本apk时,有时候它可以正常工作,有时却根本没有。

任何可能导致这种情况的想法?

FirebaseStorage storage = FirebaseStorage.getInstance();
        StorageReference storageRef = storage.getReferenceFromUrl("gs://manager-plus.appspot.com");
        StorageReference riversRef = storageRef.child("media/" + mediaDataList.get(i).name+SystemClock.elapsedRealtime());
        Uri uri;
        if (mediaDataList.get(i).type == 1)
            uri = Uri.fromFile(LoadBitmaps.saveBitmap(LoadBitmaps.decodeSampledBitmap(new File(mediaDataList.get(i).url), 100, 100)));
        else uri = Uri.fromFile(new File(mediaDataList.get(i).url));
        uploadTask = riversRef.putFile(uri);
        uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    Long size = Long.parseLong(mediaDataList.get(i).size) + Prefs.getInstance(getApplicationContext()).getSize();
                    if (Double.parseDouble(formatSize(size)) <= 2.0) {
                        Prefs.getInstance(getApplicationContext()).setSize(Long.parseLong(mediaDataList.get(i).size) + Prefs.getInstance(getApplicationContext()).getSize());
                        DataOnline dataOnline = new DataOnline();
                        dataOnline.link = String.valueOf(taskSnapshot.getDownloadUrl());
                        dataOnline.type = mediaDataList.get(i).type;
                        dataOnline.name= mediaDataList.get(i).name;
                        dataOnline.save();
                    } else {
                        Toast.makeText(getApplicationContext(), "Please subscribe to the paid version", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                        Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_LONG).show();
                    }
                })
                .addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                        //calculating progress percentage
                        double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
                        build.setProgress(100, (int) progress, false);
                        notificationManager.notify(101, build.build());
                    }
                });

谢谢,

1 个答案:

答案 0 :(得分:1)

经过这么多的调试,结果发现问题不在于firebase;它实际上是由于活跃的android。我用来在本地缓存链接的库。

因此,对于遇到此问题的任何人: 请先检查一下: developer.android.com/studio/build/shrink-code.html

在我的情况下,我使用糖ORM而不是activeandroid,我的问题解决了。

祝你好运