如何将数据从Firebase存储到本机GearVR Framework?

时间:2018-01-08 15:37:15

标签: android firebase-storage gear-vr

我想从数据库加载不同的立方体贴图。我使用的代码如下,但它无效。它每次都会崩溃。 我无法获得Android中主要外部存储的路径。有谁知道如何将数据从数据库存储到本机GearVR框架?

public class SampleActivity extends GVRActivity {

    final File externalFilesDir = getExternalFilesDir(null);
    private SampleMain main;
    private long lastDownTime = 0;

    //ref to storage firebase
    private StorageReference cubemap_ref;

    @Override
    protected void onCreate(Bundle icicle) {

        FirebaseStorage storage = FirebaseStorage.getInstance();
        StorageReference storageRef = storage.getReference();
        cubemap_ref = storageRef.child("cubemaps/cubemap_example.zip");


        final long TEN_MEGABYTE = 1024 * 1024 * 10;
        cubemap_ref.getBytes(TEN_MEGABYTE).addOnSuccessListener(new OnSuccessListener<byte[]>() {
            @Override
            public void onSuccess(byte[] bytes) {
                File file = new File(externalFilesDir.getAbsolutePath(), "cubemap.zip");
                try {
                    OutputStream os = new FileOutputStream(file);
                    os.write(bytes);
                    os.close();
                } catch (IOException e) {
                    android.util.Log.w("ExternalStorage", "Error writing " + file, e);
                }
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(Exception exception) {
                // Handle any errors
            }
        });
        super.onCreate(icicle);
        main = new SampleMain(this);
        setMain(main, "gvr.xml");
    }
}

提前致谢。

1 个答案:

答案 0 :(得分:0)

我不知道原因,但此代码现在可以使用。