我使用 Cloud Storage 通过获取文件的下载 url 来上传任何文件。根据云存储文档的建议代码如下:
获取下载网址
上传文件后,您可以通过调用 StorageReference 上的 getDownloadUrl() 方法获取下载文件的 URL:
final StorageReference ref = storageRef.child("images/mountains.jpg"); uploadTask = ref.putFile(file); Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() { @Override public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } // Continue with the task to get the download URL return ref.getDownloadUrl(); } }).addOnCompleteListener(new OnCompleteListener<Uri>() { @Override public void onComplete(@NonNull Task<Uri> task) { if (task.isSuccessful()) { Uri downloadUri = task.getResult(); } else { // Handle failures // ... } } });
当我将此代码添加到我的项目中时,Android Studio 编译器会给我“未经检查的调用”警告。我只是想逃避这个警告。我怎么能逃脱?编译器警告结果如下:
where TResult is a type-variable:
TResult extends Object declared in class Task
/Users/macbook/Documents/AndroidStudioProjects/Instagram/app/src/main/java/com/app/instagram/PostActivity.java:233: warning: [unchecked] unchecked call to <ContinuationResultT>continueWithTask(Continuation<ResultT,Task<ContinuationResultT>>) as a member of the raw type StorageTask
uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
^
感谢您的帮助...