Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val intent = Intent(Intent.ACTION_GET_CONTENT)
- intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
- intent.addCategory(Intent.CATEGORY_OPENABLE)
- intent.type = "image/*"
- startActivityForResult(intent, PICK_IMAGE_MULTIPLE);
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
- try {
- // When an Image is picked
- if (requestCode == PICK_IMAGE_MULTIPLE && resultCode == RESULT_OK && null != data) {
- // Get the Image from data
- val filePathColumn = arrayOf(MediaStore.Images.Media.DATA)
- imagesEncodedList = ArrayList()
- if (data.data != null) {
- val mImageUri: Uri = data.data!!
- // val file = File(mImageUri.path)
- // Get the cursor
- val cursor: Cursor? = activity?.contentResolver?.query(mImageUri,
- filePathColumn, null, null, null)
- // Move to first row
- cursor?.moveToFirst()
- Toast.makeText(context, "Rows : " + cursor?.count.toString(), Toast.LENGTH_LONG)
- .show()
- val columnIndex = cursor!!.getColumnIndex(filePathColumn[0])
- imageEncoded = cursor.getString(columnIndex)
- Toast.makeText(context, "Image Encoded : $imageEncoded", Toast.LENGTH_LONG)
- .show()
- cursor.close()
- // val mArrayUri = ArrayList<Uri>()
- // mArrayUri.add(mImageUri)
- // ga = GalleryAdapter(applicationContext, mArrayUri)
- // gvGallery!!.adapter = galleryAdapter
- // gvGallery!!.verticalSpacing = gvGallery!!.horizontalSpacing
- // val mlp = gvGallery!!
- // .layoutParams as ViewGroup.MarginLayoutParams
- // mlp.setMargins(0, gvGallery!!.horizontalSpacing, 0, 0)
- } else {
- if (data.clipData != null) {
- val mClipData: ClipData? = data.clipData
- val mArrayUri: ArrayList<Uri> = ArrayList<Uri>()
- for (i in 0 until mClipData?.itemCount!!) {
- val item = mClipData.getItemAt(i)
- val uri: Uri = item.uri
- mArrayUri.add(uri)
- // Get the cursor
- val cursor: Cursor? = activity?.contentResolver?.query(uri, filePathColumn, null, null, null)
- // Move to first row
- cursor?.moveToFirst()
- val columnIndex: Int = cursor!!.getColumnIndex(filePathColumn[0])
- imageEncoded = cursor.getString(columnIndex)
- Toast.makeText(context, "Rows : " + imageEncoded, Toast.LENGTH_LONG)
- .show()
- (imagesEncodedList as ArrayList<String>).add(imageEncoded!!)
- cursor.close()
- }
- Log.v(Companion.TAG, "Selected Images" + mArrayUri.size.toString())
- }
- }
- } else {
- Toast.makeText(context, "You haven't picked Image",
- Toast.LENGTH_LONG).show()
- }
- } catch (e: Exception) {
- Toast.makeText(context, "Something went wrong", Toast.LENGTH_LONG)
- .show()
- Log.e(Companion.TAG, e.toString())
- }
- super.onActivityResult(requestCode, resultCode, data)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement