Skip to content

Instantly share code, notes, and snippets.

@msomu
Last active April 5, 2018 15:08
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 msomu/d513d68127453dcd5bb548ae97f612d1 to your computer and use it in GitHub Desktop.
Save msomu/d513d68127453dcd5bb548ae97f612d1 to your computer and use it in GitHub Desktop.
Choose Image from Gallery
public int REQUEST_IMAGE_GET = 104
class MainActivity extends AppCompatActivity {
private void selectImage() {
Intent intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "image/*"
if (intent.resolveActivity(packageManager) != null) {
startActivityForResult(intent, REQUEST_IMAGE_GET)
}
}
@override void onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
if (resultCode != RESULT_CANCELED) {
if (requestCode == REQUEST_IMAGE_GET && resultCode == Activity.RESULT_OK) {
val fullPhotoUri = data.data
//imageView.setImageURI(fullPhotoUri)
}
}
}
}
const val REQUEST_IMAGE_GET = 104
class MainActivity : AppCompatActivity() {
private fun selectImage() {
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "image/*"
if (intent.resolveActivity(packageManager) != null) {
startActivityForResult(intent, REQUEST_IMAGE_GET)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode != RESULT_CANCELED) {
if (requestCode == REQUEST_IMAGE_GET && resultCode == Activity.RESULT_OK) {
val fullPhotoUri = data?.data
//imageView.setImageURI(fullPhotoUri)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment