目標
做一個安卓App,能夠從相簿裡選擇照片.
操作步驟使用AndroidStudio新建一個安卓工程 在主介面中增加顯示圖片控制元件和操作按鈕用程式碼呼叫相簿顯示private fun openAlbum() { val intent = Intent() intent.action = Intent.ACTION_PICK intent.type = "image/*" startActivityForResult(intent, 2)}override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { val photoPath: String? if (requestCode == 2 && resultCode == RESULT_OK) { data?.data?.let { photoPath = UriUtil.getRealPathFromUri(this, it) Glide.with(this).load(photoPath).into(imageView) } } super.onActivityResult(requestCode, resultCode, data)}見證成果
免費原始碼
https://gitee.com/cxyzy1/camera_album_demo
最新評論