'kotlin fragment in imagecropper not working
hi guys sory for my english not good :)
I write in fragment this code is not working and ı create new project and write this code in empty activity(is not activityfragment) is working
I'm thinking onActivityResult primary working but secondary not working
fragmentActivity logchat ->
0
1
2
3
4
999
emtyactivity logchat ->
0
1
2
3
4
999
1
5
6
7
8
9
10
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
println("1")
when (requestCode) {
GALLERY_REQUEST_CODE -> {
println("2")
if (resultCode == Activity.RESULT_OK) {
data?.data?.let { uri ->
println("3")
launchImageCrop(uri)
}
}
else{
Log.e(TAG, "Image selection error: Couldn't select that image from memory." )
}
}
CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE -> {
println("5")
val result = CropImage.getActivityResult(data)
if (resultCode == Activity.RESULT_OK) {
println("6")
setImage(result.uri)
}
else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Log.e(TAG, "Crop error: ${result.getError()}" )
}
}
}
}
private fun setImage(uri: Uri){
println("7")
Glide.with(this)
.load(uri)
.into(binding.imageView5)
selectedPicture=uri
println("8")
val storage= FirebaseStorage.getInstance()
val reference=storage.reference
val imagesReference=reference.child(UserUID)
imagesReference.putFile(selectedPicture!!).addOnSuccessListener { taskSnapshop->
println("9")
object : CountDownTimer(10000,1000){
override fun onFinish() {
val uploadPictureReference= FirebaseStorage.getInstance().reference.child(UserUID)
uploadPictureReference.downloadUrl.addOnSuccessListener { uri->
println("10")
println(uri.toString())
userphotohash.put("UserProfilePhoto",uri.toString())
db.collection("users").document(UserUID).update(userphotohash)
}
}
override fun onTick(millisUntilFinished: Long) {//her coundownda olması istenilen görevi yapıyor
}
}.start()
}
}
private fun launchImageCrop(uri: Uri){
println("4")
CropImage.activity(uri)
.setGuidelines(CropImageView.Guidelines.ON)
.setAutoZoomEnabled(false)
.setMaxCropResultSize(800,800)
.setCropShape(CropImageView.CropShape.RECTANGLE) // default is rectangle
.start(this)
println("999")
}
private fun pickFromGallery() {
println("0")
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
intent.type = "image/*"
val mimeTypes = arrayOf("image/jpeg", "image/png", "image/jpg")
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
startActivityForResult(intent, GALLERY_REQUEST_CODE)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
