Last active
April 5, 2018 15:08
-
-
Save msomu/d513d68127453dcd5bb548ae97f612d1 to your computer and use it in GitHub Desktop.
Choose Image from Gallery
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
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) | |
} | |
} | |
} | |
} |
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
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