Created
November 8, 2017 10:37
-
-
Save mockiemockiz/e459d0d41e0d32dcbbd66dff5664b14d to your computer and use it in GitHub Desktop.
multiple upload android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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