-2

I am creating an android activity for browsing the images from gallery. But it's taking only images from other folders but not images from the Camera folder.

4127157
  • 1,438
  • 2
  • 15
  • 28

1 Answers1

0

This code in your button on click

Yourbotton.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {

                    AlertDialog.Builder alertdialog1 =new AlertDialog.Builder(EditProfileActivity.this);
                    alertdialog1.setMessage("Please select a Profile image");               

                    alertdialog1.setNegativeButton("CAMERA", new DialogInterface.OnClickListener() {



                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            Intent cameraIntent = new Intent(
                                    android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

                            startActivityForResult(cameraIntent,CAMERA_REQUEST);




            }
            });
            alertdialog1.setNeutralButton("GALLERY",new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {




                            Intent i = new Intent(Intent.ACTION_PICK,            
                                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

                        startActivityForResult(i, RESULT_LOAD_IMAGE);



                            }
                            });


                           alertdialog1.setPositiveButton("CLOSE",new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                     dialog.cancel();
                }
            });    


                    alertdialog1.show();
                }
            });     

This functions in outside of onCreate()

  protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
       if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  
          Bitmap photo = (Bitmap) data.getExtras().get("data");

          edpprofilepic.setScaleType(ScaleType.FIT_XY);
          edpprofilepic.setImageBitmap(photo);
          imagepath =  ImageWrite(photo);


       }



       else if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK 
           && null != data) {
           Uri selectedImage = data.getData();
           String[] filePathColumn = { MediaStore.Images.Media.DATA };
           Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, 
                           null, null, null);
           cursor.moveToFirst();
           int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
           String picturePath = cursor.getString(columnIndex);
           cursor.close();
          edpprofilepic.setScaleType(ScaleType.FIT_XY);
          edpprofilepic.setImageBitmap(BitmapFactory.decodeFile(picturePath));
          imagepath =  ImageWrite(BitmapFactory.decodeFile(picturePath));

        }
    }

      public String ImageWrite(Bitmap bitmap1)
     {

          String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
             OutputStream outStream = null;
             File file = new File(extStorageDirectory, "slectimage.PNG");

             try
             {

                 outStream = new FileOutputStream(file);
                 bitmap1.compress(Bitmap.CompressFormat.PNG, 100, outStream);
                 outStream.flush();
                 outStream.close();



             }
             catch (FileNotFoundException e)
             {
                 e.printStackTrace();

             } catch (IOException e)
             {
                 e.printStackTrace();

             }
             String imageInSD = "/sdcard/slectimage.PNG";

             return imageInSD;

     }

I think this is helpful to you

Siva Sonai
  • 107
  • 12