自定义相机/图库应用程序未准确显示sdcard /文件夹

时间:2012-08-17 13:43:51

标签: android android-sdcard galaxy-tab

我已经构建了一个自定义相机应用程序,可将照片保存到我的SD卡上的特定文件夹中,并有自己的图库视图,用于查看该文件夹中的照片“/ sdcard / myApp / images”

我一直在两种不同的平板电脑上进行测试,Galaxy Tab-1 10英寸和Galaxy Tab-2 10英寸。相机可以在平板电脑上正常工作,拍照并将其保存到应用创建的文件夹中。但是Tab1上的图库视图不显示该文件夹中的所有照片。选项卡-2始终显示当前文件夹中的所有照片,但选项卡-1通常仅显示上次重新启动平板电脑时该文件夹中的图像。

所以在Tab-1上,如果我在该文件夹中没有照片,然后用相机拍摄两张照片并切换到图库视图,则显示没有照片。如果我然后重新启动,并转到图库视图我看到两张照片,但如果我切换到相机并拍摄另一张照片,画廊只显示原来的两张,直到我重新启动。

适用于Android 3.2 +但3.1 nope!

有什么想法吗?

将光标发送到galleryView的构造函数中的适配器:

 // Set up an array of the Thumbnail Image ID column we want
    String[] projection = {MediaStore.Images.Media._ID};
    // Create the cursor pointing to the SDCard
    cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection, // Which columns to return
            MediaStore.Images.Media.DATA + " like ? ",
            new String[] {"%LC/images%"},  
            MediaStore.Images.Media._ID + " DESC");


    // Get the column index of the Thumbnails Image ID
    columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);


    ga.setAdapter(new GallAdapter(this,cursor,columnIndex));

addapter:

public class GallAdapter extends BaseAdapter {
    public Cursor cursor;
    private int columnIndex;
    private Context context;
    int imageBackground;
    String url;
    Uri uri;
    int originalImageId;
    int imageID;
    int columnData;
    ViewGroup myp;
    ImageView d;

    public GallAdapter(Context ctx, Cursor cur, int cIn ) {
        context = ctx;
        columnIndex = cIn;

        cursor = cur;
        Log.v("GallAdapter", "COUNT:"+getCount());
    }

    @Override
    public int getCount() {

        return cursor.getCount();
    }

    @Override
    public Object getItem(int position) {

        return position;
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        myp = parent;
        View v;
        if(convertView ==null){
            v = LayoutInflater.from(context).inflate(R.layout.galitem, parent, false);
        }else{
            v = convertView;
        }


        ImageView photo = (ImageView) v.findViewById(R.id.imageView);
        ImageView border = (ImageView) v.findViewById(R.id.borderView);
        d = (ImageView) v.findViewById(R.id.delView);



        // Move cursor to current position
        cursor.moveToPosition(position);

        // Get the current value for the requested column
        imageID = cursor.getInt(columnIndex);
        // obtain the image URI
        uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
        url = uri.toString();
        // Set the content of the image based on the image URI
        originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
        Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(),
                        originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
        photo.setImageBitmap(b);

        photo.setScaleType(ImageView.ScaleType.FIT_CENTER); 
        d.setTag(uri);
        d.setOnClickListener(new OnClickListener(){


            public void onClick(View v) {

                String path = getRealPathFromURI((Uri) v.getTag());
                alertBox("Warning!", "Are you sure you want to delete this photo?", path, v);


            }


        });

        return v;
    }

这又适用于tab-2(os 4.0)和tab-1,现在固件是在tab-1和os从3.1到3.2更新的,但为什么它不能正常工作..

1 个答案:

答案 0 :(得分:1)

尝试此操作以刷新媒体文件。

this._context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/Hugg/" + name)));