1

我正在尝试使用此方法保存从图库导入的图像的路径:

case R.id.media:
        Intent i = new Intent(
                Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

        startActivityForResult(i, RESULT_LOAD_IMAGE);
        return true;

这是 on 活动结果方法:

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

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
        final 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();
        mImage = picturePath;
        ImageView imageView = (ImageView) findViewById(R.id.note_image);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
        imageView.setClickable(true);
        imageView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent viewImageIntent = new Intent(android.content.Intent.ACTION_VIEW, selectedImage);
                        startActivity(viewImageIntent);
                    }
                });

    }


}

这是填充字段方法:

mImage =(note.getString(
                note.getColumnIndexOrThrow(NotesDbAdapter.KEY_IMAGE)));

但这不起作用,路径没有保存,当我关闭活动并再次启动活动时,图像消失了。我怎样才能解决这个问题?

4

0 回答 0