- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
task.getResult().getDownloadUrl().toString() 方法不起作用,在 android studio 中,我是 Android 领域的新手,我可以找人帮我解决问题吗???这是我的 setupActivity 类的完整代码。
task.getResult().getDownloadUrl().toString() 方法不起作用,在 android studio 中,我是 Android 领域的新手,我可以找人帮我解决问题吗???这是我的 setupActivity 类的完整代码。
package com.example.ihsan;
import android.app.ProgressDialog;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.squareup.picasso.Picasso;
import com.theartofdev.edmodo.cropper.CropImage;
import com.theartofdev.edmodo.cropper.CropImageView;
import java.util.HashMap;
import java.util.Objects;
import de.hdodenhof.circleimageview.CircleImageView;
public class SetupActivity extends AppCompatActivity {
private EditText UserName, FullName, CountryName;
private Button SaveInformationbuttion;
private CircleImageView ProfileImage;
private ProgressDialog loadingBar;
private FirebaseAuth mAuth;
private DatabaseReference UsersRef;
private StorageReference UserProfileImageRef;
String currentUserID;
final static int Gallery_Pick = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup);
mAuth = FirebaseAuth.getInstance();
currentUserID = mAuth.getCurrentUser().getUid();
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID);
UserProfileImageRef = FirebaseStorage.getInstance().getReference().child("Profile Images");
UserName = (EditText) findViewById(R.id.setup_username);
FullName = (EditText) findViewById(R.id.setup_full_name);
CountryName = (EditText) findViewById(R.id.setup_country_name);
SaveInformationbuttion = (Button) findViewById(R.id.setup_information_button);
ProfileImage = (CircleImageView) findViewById(R.id.setup_profile_image);
loadingBar = new ProgressDialog(this);
SaveInformationbuttion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SaveAccountSetupInformation();
}
});
ProfileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
Intent galleryIntent = new Intent();
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent, Gallery_Pick);
}
});
ProfileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent galleryIntent = new Intent();
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent, Gallery_Pick);
}
});
UsersRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
if (dataSnapshot.hasChild("profileimage")) {
String image = dataSnapshot.child("profileimage").getValue().toString();
Picasso.with(SetupActivity.this).load(image).placeholder(R.drawable.profile).into(ProfileImage);
}
}
else
{
Toast.makeText(SetupActivity.this, "Please select profile image first...", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==Gallery_Pick && resultCode==RESULT_OK && data!=null)
{
Uri ImageUri = data.getData();
CropImage.activity()
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(1, 1)
.start(this);
}
if(requestCode==CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE)
{
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if(resultCode == RESULT_OK)
{
loadingBar.setTitle("Profile Image");
loadingBar.setMessage("Please wait, while we updating your profile image...");
loadingBar.show();
loadingBar.setCanceledOnTouchOutside(true);
Uri resultUri = result.getUri();
StorageReference filePath = UserProfileImageRef.child(currentUserID + ".jpg");
filePath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull final Task<UploadTask.TaskSnapshot> task)
{
if(task.isSuccessful())
{
Toast.makeText(SetupActivity.this, "Profile Image stored successfully...", Toast.LENGTH_SHORT).show();
final String downloadUrl = task.getResult().getDownloadUrl().toString();
UsersRef.child("profileimage").setValue(downloadUrl)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task)
{
if(task.isSuccessful())
{
Intent selfIntent = new Intent(SetupActivity.this, SetupActivity.class);
startActivity(selfIntent);
Toast.makeText(SetupActivity.this, "Profile Image stored to Successfully...", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
else
{
String message = task.getException().getMessage();
Toast.makeText(SetupActivity.this, "Error Occurred: " + message, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
}
});
}
else
{
Toast.makeText(this, "Error Occurred: Image can not be cropped. Try Again.", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
}
private void SaveAccountSetupInformation() {
String username = UserName.getText().toString();
String fullname = FullName.getText().toString();
String country = CountryName.getText().toString();
if (TextUtils.isEmpty(username)) {
Toast.makeText(this, "Please write your username...", Toast.LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(fullname)) {
Toast.makeText(this, "Please write your full name...", Toast.LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(country)) {
Toast.makeText(this, "Please write your country...", Toast.LENGTH_SHORT).show();
} else {
loadingBar.setTitle("Saving Information");
loadingBar.setMessage("Please wait, while we are creating your new Account...");
loadingBar.show();
loadingBar.setCanceledOnTouchOutside(true);
HashMap userMap = new HashMap();
userMap.put("username", username);
userMap.put("fullname", fullname);
userMap.put("country", country);
userMap.put("status", "Hey there, I'm using IHSAN , developed by Mohamed EL Ghazali.");
userMap.put("gender", "none");
userMap.put("dob", "none");
userMap.put("relationshipstatus", "none");
UsersRef.updateChildren(userMap).addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task)
{
if(task.isSuccessful())
{
SendUserToMainActivity();
Toast.makeText(SetupActivity.this, "your Account is created Successfully.", Toast.LENGTH_LONG).show();
loadingBar.dismiss();
}
else
{
String message = task.getException().getMessage();
Toast.makeText(SetupActivity.this, "Error Occurred: " + message, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
}
private void SendUserToMainActivity() {
Intent mainIntent = new Intent(SetupActivity.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
finish();
}
}
最佳答案
检查这个文档;为 getDownloadUrl() 设置完整的监听器 https://firebase.google.com/docs/storage/android/download-files?authuser=0#download_data_via_url
//it is better not to use space in child name
StorageReference storageRef = FirebaseStorage.getInstance().getReference()
.child("ProfileImages")
.child(currentUserID + ".jpg")
storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'path/to/aFile'
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
关于android - task.getResult().getDownloadUrl().toString() 方法不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58054352/
Uri downloaduri=taskSnapshot.getDownloadUrl();//here i cant use getdownloadurl() function
我想知道是否 getDownloadUrl在 Firebase 存储/谷歌云存储(一种获取存储上文件的公共(public) URL 的方法)上是一项付费操作。即使在通读之后 the documenta
为了在Cloud Firestore中创建配置文件信息,我尝试使用 NonExistingProfileForm 。 照片是从画廊中选择的,并上传到了Firebase存储中,但我似乎无法获取它的URL
我有一个函数,首先将图像保存到 Firebase,然后返回下载网址。现在我可以取回url(请参阅return url),但我不知道如何为整个函数返回它,因为它是嵌套,并且由于此函数异步运行,如果在 g
我尝试将图像上传到 Firebase 存储,然后从存储中获取下载网址,以便将其保存到我的数据库中。 注释掉的行有效,所以我知道它是“getDownloadURL”函数或我的存储引用中的问题。我有一个类
我正在将 pdf 上传到 Firebase Storage,并希望获取其下载网址。我正在使用以下代码: @Override protected void onActivityResult(int re
这个问题已经有答案了: How to get URL from Firebase Storage getDownloadURL (14 个回答) 已关闭 4 年前。 我正在尝试遵循有关“如何制作 Wh
通话时 task.getResult().getDownloadUrl().toString(); 我在 getDownloadUrl() 上遇到错误,不知道为什么?显示红线并且无法解析符号 if (
private void uploadImageToFirebaseStorage() { StorageReference profileImageRef = Firebas
这个问题在这里已经有了答案: How to return DataSnapshot value as a result of a method? (6 个答案) 关闭 4 年前。 此方法应该返回 d
到目前为止,从 Firebase 中的存储文件中获取 url 的方法,我曾经这样做过taskSnapshot.getDownloadUrl,但现在已弃用,我应该使用哪种方法? 最佳答案 正如 Doug
private void uploadImageToFirebaseStorage() { StorageReference profileImageRef = Firebas
要将图像上传到Firebase Storage,我将addOnSuccessListener附加到StorageReference的实例上。在覆盖 onSuccess 方法时,我在 taskSnaps
我正在尝试使用新的@angular/fire 5.1.0使用 AngularFireStorage 查看上传到 firebase 的图像。我曾经能够在 angularfire2 中使用 task.do
你能帮我解决这个错误吗? getDownloadUrl();说无法解析 getDownloadUrl() 的符号变量。我知道 getDownloadUrl(); 已被弃用,我尝试阅读更新后的文档,但我
private void storeFirestore(@NonNull Task task, String user_name) { Uri download_uri; if(tas
我在将图片上传到 Firebase 时遇到问题。 当我上传图像时,我得到一个 taskSnapshot.getDownloadUrl() token ,当我查看 firebase 存储时,有一个不同的
根据我读过的文档 ref.getDownloadURL(); 应该返回一个我可以在 img src 中使用的链接。 这是我的代码:这就是我启动 firebase 的方式: this.storage =
let storage = firebase.storage(); let storageRef = storage.ref("EnglishVideos/" + movieTitle + "/" +
真的需要帮助,这是我的 Firebase 存储安全规则 service firebase.storage { match /b/shoppinglist-XXXX.appspot.com/o {
我是一名优秀的程序员,十分优秀!