Is there any way to remove the link and only get the file name of the file in the code? Im trying to access to load a model in my app that is created in android studio
This one doesn't work because it provides a link instead the name of the file
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference modelRef = storage.getReference().child(myPlants.getPlantModel());
This code works
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference modelRef = storage.getReference().child(pre4.glb);
Is there a way to get the file name only and not the token? Please help.
The assigned text in the getPlantModel is the link.
Database Screenshot
public class PlantAR extends AppCompatActivity {
private ProgressDialog progressDialog;
Button downloadButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_plant_ar);
Intent intent = getIntent();
MyPlants myPlants = (MyPlants) intent.getSerializableExtra("plants");
FirebaseApp.initializeApp(this);
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference modelRef = storage.getReference().child("pre6.glb");
ArFragment arFragment = (ArFragment) getSupportFragmentManager()
.findFragmentById(R.id.fragmentAR);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Model downloading Please Wait...........");
downloadButton = findViewById(R.id.downloadModel);
findViewById(R.id.downloadModel)
.setOnClickListener(v -> {
try {
File file = File.createTempFile("pre6", "glb");
progressDialog.show();
modelRef.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
buildModel(file);
}
});
} catch (IOException e) {
e.printStackTrace();
}
});
arFragment.setOnTapArPlaneListener((hitResult, plane, motionEvent) -> {
AnchorNode anchorNode = new AnchorNode(hitResult.createAnchor());
anchorNode.setRenderable(renderable);
arFragment.getArSceneView().getScene().addChild(anchorNode);
});
}
private ModelRenderable renderable;
private void buildModel(File file) {
RenderableSource renderableSource = RenderableSource
.builder()
.setSource(this, Uri.parse(file.getPath()), RenderableSource.SourceType.GLB)
.setRecenterMode(RenderableSource.RecenterMode.ROOT)
.build();
ModelRen开发者_StackOverflow中文版derable
.builder()
.setSource(this, renderableSource)
.setRegistryId(file.getPath())
.build()
.thenAccept(modelRenderable -> {
downloadButton.setVisibility(View.GONE);
progressDialog.dismiss();
Toast.makeText(this, "Model built", Toast.LENGTH_SHORT).show();;
renderable = modelRenderable;
});
}
精彩评论