本文整理汇总了Java中com.google.firebase.storage.OnProgressListener类的典型用法代码示例。如果您正苦于以下问题:Java OnProgressListener类的具体用法?Java OnProgressListener怎么用?Java OnProgressListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OnProgressListener类属于com.google.firebase.storage包,在下文中一共展示了OnProgressListener类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadStory
import com.google.firebase.storage.OnProgressListener; //导入依赖的package包/类
private void uploadStory(byte[] data){
mProgressTextView.setText("");
StorageMetadata metadata = new StorageMetadata.Builder()
.setContentType("image/jpeg")
.build();
String filename = String.valueOf(System.currentTimeMillis());
StorageReference storageReference = FirebaseStorage.getInstance().getReference();
StorageReference photoReference = storageReference.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.child(filename);
photoReference.putBytes(data, metadata)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
saveStory(taskSnapshot);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
showSnackBar("Failed to upload photo");
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot snapshot) {
int progress = (int) ((100.0 * snapshot.getBytesTransferred()) / snapshot.getTotalByteCount());
mProgressTextView.setText("Upload is " + progress + "% done");
}
});
}