毕加索无法从Firebase加载网址

时间:2019-03-22 22:14:17

标签: picasso

我阅读了与此主题相关的其他威胁,但仍然无法解决, 毕加索不会从URL加载我的图像,照片会上传到Firebase存储,数据库也会读取照片,但是在应用程序上毕加索不会上传照片,但占位符正在加载选定的可绘制图像。在某个地方,我做错了事,但我不知道在哪里。 如果您客气,请协助我。

//这是清单中的权限

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

// xml文件

 <de.hdodenhof.circleimageview.CircleImageView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/profile_imageid"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_centerInParent="true"
            app:civ_border_width="2dp"


            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="16dp"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginStart="16dp"
            app:layout_constraintHorizontal_bias="0.498"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toTopOf="@+id/displayNameId"
            android:layout_marginTop="24dp"
            app:layout_constraintTop_toTopOf="parent"
            android:src="@drawable/profile_img"/>


        mcurentUser=FirebaseAuth.getInstance().currentUser
        var userId = mcurentUser!!.uid
        mDb =FirebaseDatabase.getInstance().reference.child("Users").child(userId)
        mstorage = FirebaseStorage.getInstance().reference
        profileimgid = findViewById(R.id.profile_imageid) as CircleImageView


 mDb!!.addValueEventListener(object : ValueEventListener{

            override fun onDataChange(dataSnapshot: DataSnapshot) {
                var displayName = dataSnapshot.child("display_name").value
                var image = dataSnapshot.child("image").value.toString()
                var status = dataSnapshot.child("status").value
                var thumbnails = dataSnapshot.child("thumb_image").value.toString()

                changestatusId.setHint(status.toString())
                displayNameId.text = displayName.toString()
                if (!image.equals("default")){
                    Picasso.get().load(image)
                      //  .centerCrop()
                        .placeholder(R.drawable.profile_img)
                        .into(profile_imageid)
                }
                }





            override fun onCancelled(databaseError: DatabaseError) {


            }


    override fun onActivityResult(requestCode: Int, resultCode: Int, data2: Intent?) {
        super.onActivityResult(requestCode, resultCode, data2)
        if(requestCode==GALERY_ID &&resultCode==Activity.RESULT_OK){
            var image: Uri = data2!!.data
CropImage.activity(image).setAspectRatio(1,1).start(this)
        }
        if (requestCode==CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            val result = CropImage.getActivityResult(data2)
            if (resultCode == Activity.RESULT_OK) {
                val resultUri = result.uri
                var userId = mcurentUser!!.uid
                var thumbFile = File(resultUri.path)
                var thumbBitmap = Compressor(this)
                    .setMaxHeight(100)
                    .setMaxWidth(100)
                    .setQuality(65)
                    .compressToBitmap(thumbFile)




//Upload to Firebase

  var byteArray = ByteArrayOutputStream()
                thumbBitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArray)
                var thumbByteArray = byteArray.toByteArray()

                var filePath = mstorage!!.child("chat_profile_images").child(userId + ".jpg")


  var thumbfilePath = mstorage!!.child("chat_profile_images")
                    .child("thumbs")

                    .child(userId + ".jpg")

//Download

filePath.putFile(resultUri).addOnCompleteListener { task: Task<UploadTask.TaskSnapshot> ->

                    if (task.isSuccessful) {
                        var donwloadUrl = task.result!!.getStorage().downloadUrl.toString()


                        var uploadTask: UploadTask = thumbfilePath
                            .putBytes(thumbByteArray)
                        uploadTask.addOnCompleteListener { task: Task<UploadTask.TaskSnapshot> ->
                            var thumbUrl = task.result!!.getStorage().downloadUrl.toString()

  if (task.isSuccessful) {
                                var updateObj = HashMap<String, Any>()
                                updateObj.put("image", donwloadUrl)
                                updateObj.put("thumb_image", thumbUrl)


                                //save profileimage
                                mDb!!.updateChildren(updateObj).addOnCompleteListener { task: Task<Void> ->
                                    if (task.isSuccessful) {
                                        Toast.makeText(this, "Profile image saved", Toast.LENGTH_LONG).show()
                                    }else{

                                    }
                                }
                            }else{

                            }




0 个答案:

没有答案