Android Studio,Kotlin:上传图片并显示
它打开画廊,但是当我选择一张照片时,图像不会改变。 这是我的代码告诉我我哪里错了
@SuppressLint("NewApi", "ResourceType") override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == SELECTED_PICTURE){ if (resultCode == Activity.RESULT_OK) { val uri : Uri = data!!.data val projection = arrayOf(MediaStore.Images.Media.DATA) val cursor : Cursor = contentResolver.query( uri, projection,null,null) cursor.moveToFirst() val columnIndex : Int = cursor.getColumnIndex(projection[0]) val filePath : String = cursor.getString(columnIndex) cursor.close() val yourSelected_image : Bitmap = BitmapFactory.decodeFile(filePath) val d : Drawable = BitmapDrawable(yourSelected_image) }
- Kotlin对象/单例的方法是否同步?
- 使用kotlin&greendao的Android Studio 3.0 Proguard将返回ClassLookupException
- 在Kotlin中使用GsonTypeAdapter的AutoValue
- Android Studio kaptDebugKoltin内部编译器错误
- Kotlin和Android TextWatcher具有CharSequence / String替换功能
- Observable.combineLatest更新到RxJava 2.xx后导致错误 – 不能推断类型
- 原生Android应用程序的定义是什么?
- Kotlin || 无法将库添加到我的应用程序?
- 更新Android Studio后无法打开项目