views:

52

answers:

2

friends,

i am trying to display image from gallery now i want to put check if selected 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;
                }
            }
+1  A: 

please have a look here

Asahi
+1  A: 

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 is the case with audio and video files it automatically filters your required files.

UMMA