Matagal na akong di nakapag android boss, pero try mo 'to baka mag work sayo
[CODE lang="java" title="fileUpload()"]
if (filePath != null) {
// Code for showing progressDialog while uploading
ProgressDialog progressDialog
= new ProgressDialog(this);
progressDialog.setTitle("Uploading...");
progressDialog.show();
// Defining the child of storageReference
StorageReference ref
= storageReference
.child(
"images/"
+ UUID.randomUUID().toString());
// adding listeners on upload
// or failure of image
ref.putFile(filePath)
.addOnSuccessListener(
new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(
UploadTask.TaskSnapshot taskSnapshot)
{
// Image uploaded successfully
// Dismiss dialog
progressDialog.dismiss();
Toast
.makeText(MainActivity.this,
"Image Uploaded!!",
Toast.LENGTH_SHORT)
.show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e)
{
// Error, Image not uploaded
progressDialog.dismiss();
Toast
.makeText(MainActivity.this,
"Failed " + e.getMessage(),
Toast.LENGTH_SHORT)
.show();
}
})
.addOnProgressListener(
new OnProgressListener<UploadTask.TaskSnapshot>() {
// Progress Listener for loading
// percentage on the dialog box
@Override
public void onProgress(
UploadTask.TaskSnapshot taskSnapshot)
{
double progress
= (100.0
* taskSnapshot.getBytesTransferred()
/ taskSnapshot.getTotalByteCount());
progressDialog.setMessage(
"Uploaded "
+ (int)progress + "%");
}
});
} [/CODE]