I build custom gallery for photos only. I taking photos from sdcard with this class:
Using java Syntax Highlighting
- public class Photos {
- public static final String PHOTO_BUCKET_NAME =
- Environment.getExternalStorageState().toString() + "/DCIM/Camera";
- public static final int PHOTO_BUCKET_ID = getBucketId(PHOTO_BUCKET_NAME);
- public static int getBucketId(String path) {
- return path.toLowerCase().hashCode();
- }
- public static List<String> getPhotos(Context context) {
- final String[] projection = {MediaStore.Images.Media.DATA};
- final String selection = MediaStore.Images.Media.BUCKET_ID;
- Cursor c = context.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);
- List<String> result = new ArrayList<String>(c.getCount());
- if (c.moveToFirst()) {
- int dataColumn = c.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
- do {
- String data = c.getString(dataColumn);
- result.add(data);
- } while (c.moveToNext());
- }
- c.close();
- return result;
- }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
And set adapter to gallery:
Using java Syntax Highlighting
- public class ImageAdapter extends BaseAdapter {
- int GalItemBg;
- private Context mContext;
- private List<String> photoList;
- public ImageAdapter(Context c) {
- mContext = c;
- photoList = Photos.getPhotosThumbnails(c);
- TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
- GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
- typArray.recycle();
- }
- @Override
- public int getCount() {
- return photoList.size();
- }
- @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) {
- ImageView i = new ImageView(mContext);
- Bitmap bm = BitmapFactory.decodeFile(photoList.get(position));
- i.setImageBitmap(bm);
- i.setLayoutParams(new Gallery.LayoutParams(80,70));
- i.setScaleType(ImageView.ScaleType.FIT_XY);
- i.setBackgroundResource(GalItemBg);
- return i;
- }
- }
- }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
There is nothing special. When i run my app, all good it works. After that I launch camera and taking some photos, in this time my app running in background. When I back to my app, I need to see new photos. How to do it?
Thank you