毕加索无法在StorageReference的onSuccess方法中加载图像 [英] Picasso can't load image inside StorageReference's onSuccess method

查看:217
本文介绍了毕加索无法在StorageReference的onSuccess方法中加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图在运行时 onStart()方法上使用Picasso时,它通常使用来自控制台的下载链接加载Firebase中的图像。



但是,当我尝试在StorageReference onSuccess 方法中加载图片时,它就不起作用了。

这个类是扩展片段:

$ @ $ $
public void onActivityResult(int requestCode,int resultCode,Intent数据){
super.onActivityResult(requestCode,resultCode,data);

if(requestCode == GALLERY_IN&& resultCode == Activity.RESULT_OK){
isGranted = true;
String path = FireStorage.retUID()+/;
showIndProgress();
Uri uri = data.getData();

StorageReference childPathRef = FireStorage.storageRef.child(path + uri.getLastPathSegment());
publicPath onComplete(@NonNull Task< UploadTask.TaskSnapshot>
$ ){
if(task.isSuccessful()){
Picasso.with(mContext).load(task.getResult()。getDownloadUrl())$ b $ .into(profView);

Picasso.Builder build = new Picasso.Builder(mContext);
build.listener(new Picasso.Listener(){
@Override
public void onImageLoadFailed(Picasso picasso ,异常例外){
Toast.makeText(mContext,exception\\\
+ exception.toString(),Toast.LENGTH_SHORT).show();

}
});
progressDialog.dismiss();
} else {
//失败
}

}
});



$ b $ / code $ / pre
$ b

这是我的另一个Class上的FirebaseStorage实例:

  public static FirebaseStorage storage = FirebaseStorage.getInstance(); 
public static StorageReference storageRef =
storage.getReferenceFromUrl(gs://myurl.appspot.com/);

清单:

 < uses-permission android:name =android.permission.INTERNET/> 
<使用权限android:name =android.permission.ACCESS_NETWORK_STATE/>
< uses-permission android:name =android.permission.READ_EXTERNAL_STORAGE/>

我的XML布局:

 < RelativeLayout 
android:layout_width =match_parent
android:layout_height =200dp
android:background =@ drawable / gcover
机器人:ID = @ + ID / RelativeLayout的 >

< de.hdodenhof.circleimageview.CircleImageView xmlns:app =http://schemas.android.com/apk/res-auto
android:id =@ + id / profPhoto
android:clickable =true
android:layout_width =120dp
android:layout_height =120dp
android:padding =20dp
android:src =@ drawable / default_prof
android:scaleType =centerCrop
app:civ_border_color =@ color / trans
app:civ_border_width =2dp
android:layout_centerVertical =true
android:layout_centerHorizo​​ntal =true/>

< / RelativeLayout>

我的意见初始化:

  @Override 
public View onCreateView(LayoutInflater inflater,
ViewGroup容器,
Bundle savedInstanceState){
View view = inflater.inflate(R.layout。 fragment_prof,container,false);
profView =(CircleImageView)view.findViewById(R.id.profPhoto);

btn1 =(Button)view.findViewById(R.id.btn_1);
btn2 =(Button)view.findViewById(R.id.btn_2);
btn3 =(Button)view.findViewById(R.id.btn_3);
返回视图;


解决方案

> CircleImageView 转换为正常的 ImageView ,并突然生效。


When trying Picasso on the runtime onStart() method it normally loads the image from Firebase using the download link from the console.

But when I try to load an image inside StorageReference onSuccess method it just won't work.

This class is extending Fragment:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == GALLERY_IN && resultCode == Activity.RESULT_OK) {
        isGranted = true;
        String path = FireStorage.retUID() + "/";
        showIndProgress();
        Uri uri = data.getData();

        StorageReference childPathRef = FireStorage.storageRef.child(path + uri.getLastPathSegment());
        childPathRef.putFile(uri)
                .addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
                        if(task.isSuccessful()) {
                            Picasso.with(mContext).load(task.getResult().getDownloadUrl())
                                    .into(profView);

                            Picasso.Builder build = new Picasso.Builder(mContext);
                            build.listener(new Picasso.Listener() {
                                @Override
                                public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
                                    Toast.makeText(mContext, "exception\n" + exception.toString(), Toast.LENGTH_SHORT).show();

                                }
                            });
                            progressDialog.dismiss();
                        } else {
                            //failed
                        }

                    }
                });

    }

}

This is my FirebaseStorage instance on another Class:

public static FirebaseStorage storage = FirebaseStorage.getInstance();
public static StorageReference storageRef = 
                           storage.getReferenceFromUrl("gs://myurl.appspot.com/");

Manifest:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

My XML layout:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="@drawable/gcover"
    android:id="@+id/relativeLayout">

    <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/profPhoto"
        android:clickable="true"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:padding="20dp"
        android:src="@drawable/default_prof"
        android:scaleType="centerCrop"
        app:civ_border_color="@color/trans"
        app:civ_border_width="2dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

My views initialization:

@Override
public View onCreateView(LayoutInflater inflater,
                         ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_prof, container, false);
    profView = (CircleImageView) view.findViewById(R.id.profPhoto);

    btn1 = (Button) view.findViewById(R.id.btn_1);
    btn2 = (Button) view.findViewById(R.id.btn_2);
    btn3 = (Button) view.findViewById(R.id.btn_3);
    return view;
}

解决方案

I just switched from CircleImageView to a normal ImageView and it suddenly worked.

这篇关于毕加索无法在StorageReference的onSuccess方法中加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆