0

Hello !! I am trying to write a very simple android program. When I press the share button on a selected image from the image gallery a menu pops up and tells me to choose between my application and the messaging application to open the image with. When I choose my application I want it to view the image in an image view. For the part that I already done is the implicit intent when I press the share button it pops up a menu for me to choose which application I want to use. The second part is the tricky part since the image is saved on the SD Card of the phone how do I access that particular image and how do I view it in the image view ? And I am using the Android Emulator.

Sandesh
  • 1,190
  • 3
  • 23
  • 41
Mahmoud Abdel-Rahman
  • 497
  • 2
  • 10
  • 27

1 Answers1

0

first create an emulator having sdcard then how to save image in emulator

for picking an image from sdcard u can follow this tutorial

protected void onActivityResult(int requestCode, int resultCode, 
       Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

    switch(requestCode) { 
    case REQ_CODE_PICK_IMAGE:
        if(resultCode == RESULT_OK){  
            Uri selectedImage = imageReturnedIntent.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 filePath = cursor.getString(columnIndex);
            cursor.close();


            Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
            yourImageView.setImageBitmap(yourSelectedImage);
        }
    }
}

for showing that image in ur imageview use this

ImageView img=(ImageView) findViewById(R.id.ur_imageview);
Bitmap bmp = BitmapFactory.decodeFile(filePath);
img.setImageBitmap(bmp);
Community
  • 1
  • 1
Kaushik
  • 6,150
  • 5
  • 39
  • 54