how to check selected file is an image?
friends,
i am trying to display image from gallery now i want to put check if sele开发者_StackOverflow社区cted file is image then it should be displayed.
using following code any one help me out how to achieve this?
User can select video file, image file etc.. anything so i want to allow only images.
ON button click
private void SelectImageFromGallery()
{
startActivityForResult(new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI),0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch( resultCode )
{
case 0:
Log.i( "MakeMachine", "User cancelled" );
break;
case -1:
_data = data;
ShowImageInActivity();
break;
}
}
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, IMAGE_PICK);
No need to check if you want to pick only images then use above property. Same case with audio and video files, it automatically filters your required files.
精彩评论