Firebase自定义应用程序设置

时间:2017-05-16 08:43:00

标签: android firebase firebase-storage

customApp= new FirebaseApp(getApplicationContext(),"My News",<to be filled>);
    storage = FirebaseStorage.getInstance(customApp);

我是firebase的新手,以及自定义应用程序的确切用途。

我想创建一个自定义应用,使用firebase将大文件上传到Google云存储。是推荐给我的自定义应用程序吗?

4 个答案:

答案 0 :(得分:1)

无需使用customApp;

我们可以使用

storage = FirebaseStorage.getInstance("gs://<Google cloud storage bucket name>");

如果我们想要存储引用,那么

mStorageRef = storage.getReferenceFromUrl("gs://<Google cloud storage bucket name>");

答案 1 :(得分:0)

  @Override
public void onCreate() {
    super.onCreate();
    FirebaseOptions options = new FirebaseOptions.Builder()
            .setApiKey("AI...3LnY")
            .setStorageBucket("gs://f...t")
            .setApplicationId("1:356....:android:f......232")
            .build();
    customApp = FirebaseApp.initializeApp(getApplicationContext(),options,"MyApp");
    //storage
    storage = FirebaseStorage.getInstance(customApp);`enter code here`

}

答案 2 :(得分:0)

如果您是Firebase的新用户,则可能不需要自定义FirebaseApp。相反,只需使用Firebase Storage documentation中显示的FirebaseStorage.getInstance().getReference()

答案 3 :(得分:0)

Frank van Puffelen先生。 它为我工作(从谷歌云存储导入的存储桶。)

mStorageRef = FirebaseStorage.getInstance("gs://c......s").getReference();

使用firebase将文件从Google云端存储下载到本地设备。

final StorageReference downloadRef;
        downloadRef = mStorageRef.getRoot().child(downloadPath);

        try {
            File output = new File(Environment.getExternalStorageDirectory() + File.separator + Config.MY_VIDEOS_PATH);
            if (!output.exists()) {
                output.mkdir();
            }
            localFile = new File(output, downloadId);
        } catch (Exception e) {
            e.printStackTrace();
        }


        // Download and get total bytes
        downloadRef.getFile(localFile)
                .addOnProgressListener(new OnProgressListener<FileDownloadTask.TaskSnapshot>() {
                    @Override
                    public void onProgress(FileDownloadTask.TaskSnapshot taskSnapshot) {
                        showProgressNotification(title, "",
                                taskSnapshot.getBytesTransferred(),
                                taskSnapshot.getTotalByteCount());
                    }
                })
                .addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                        Log.d(TAG, "download:SUCCESS");
                        // Send success broadcast with number of bytes downloaded
                        broadcastDownloadFinished(downloadPath, taskSnapshot.getTotalByteCount());
                        showDownloadFinishedNotification(downloadPath, (int) taskSnapshot.getTotalByteCount());

                        // Mark task completed
                        taskCompleted();
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                        Log.w(TAG, "download:FAILURE", exception);
                        Log.w(TAG, "download:FAILURE", exception.getCause());

                        // Send failure broadcast
                        broadcastDownloadFinished(downloadPath, -1);
                        showDownloadFinishedNotification(downloadPath, -1);

                        // Mark task completed
                        taskCompleted();
                    }
                });