This is what I am using and it works perfect (I omited some of my
additional code that is for my own use).  I hope this helps.

public class ImageSelection extends Activity implements
View.OnClickListener  {

        private static final int SELECT_IMAGE = 0;

        private String filepath;

        Bundle fieldresults;
        Intent b;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.enteredit);

        Button selectimage = (Button) findViewById(R.id.selectimage);
                selectimage.setOnClickListener(this);

        fieldresults = new Bundle();
                b = new Intent(this, PreviewScreen.class);
        }


        //@Override
        public void onClick(View view) {
                switch (view.getId()) {
                case R.id.selectimage:
                        Intent gallery = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                        startActivityForResult(gallery, SELECT_IMAGE);
                }
        }


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

                if (resultCode == RESULT_OK)
                {
                        if (requestCode == SELECT_IMAGE)
                        {
                                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]);
                                filepath = cursor.getString(columnindex);
                                cursor.close();

                                fieldresults.putString("bitmap", filepath);
                                b.putExtras(fieldresults);

                                startActivity(b);
                                finish();
                        }
                }
        }
}

This is where I preview and choose what to do with the selected image

public class PreviewScreen extends Activity {

    private String Filepath;

    private Button saveButton;
    private Button cancelButton;

    @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.previewscreen);

        Bundle fieldresults = this.getIntent().getExtras();
                Filepath = fieldresults.getString("bitmap");

                Bitmap image = BitmapFactory.decodeFile(Filepath);
                ImageView gallerypic = (ImageView) 
findViewById(R.id.gallerypic);
                gallerypic.setImageBitmap(image);

        saveButton = (Button) findViewById(R.id.savebutton);
        cancelButton = (Button) findViewById(R.id.cancelbutton);

        cancelButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                        finish();
                }
        });

        saveButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                        appenddata();\\ this is where you do what you want with 
the
chosen image.
                                                    \\ I put my file
path in the DB so it can be accessed directly from the original
location each time.
                }
        });
    }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to