Skip to content

Instantly share code, notes, and snippets.

@mockiemockiz
Created November 8, 2017 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mockiemockiz/e459d0d41e0d32dcbbd66dff5664b14d to your computer and use it in GitHub Desktop.
Save mockiemockiz/e459d0d41e0d32dcbbd66dff5664b14d to your computer and use it in GitHub Desktop.
multiple upload android
package tigaer.inventory
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import kotlinx.android.synthetic.main.upload_motif_activity.*
import android.provider.MediaStore
import android.graphics.Bitmap
import android.net.Uri
import android.os.Build
import android.support.annotation.RequiresApi
import java.io.IOException
class UploadMotifActivity : AppCompatActivity() {
private val PICK_IMAGE_MULTIPLE = 1
private var bitmap: Bitmap? = null
private var filePath: Uri? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.upload_motif_activity)
btnAddPhots.setOnClickListener(View.OnClickListener { test() })
}
public fun test(){
val i = Intent()
i.type = "image/*"
i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
i.action = Intent.ACTION_GET_CONTENT
startActivityForResult(
Intent.createChooser(i, "android.intent.action.SEND_MULTIPLE"), 1)
}
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
var cd = data.clipData
if (cd != null) {
for (i in 0..(cd.itemCount - 1)) {
filePath = cd.getItemAt(i).uri
}
} else {
filePath = data.data
}
try {
bitmap = MediaStore.Images.Media.getBitmap(contentResolver, filePath)
imageView.setImageBitmap(bitmap)
} catch (e: IOException) {
e.printStackTrace()
}
textView2.text = filePath.toString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment