如何获得在Android设备上的所有图像(特别是SD卡)(2.1或更高) [英] How to get all images on device (sdcard particularly) on android (2.1 or greater)

查看:128
本文介绍了如何获得在Android设备上的所有图像(特别是SD卡)(2.1或更高)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里跟着教程:的http://androidsamples.blogspot.com/2009/06/how-to-display-thumbnails-of-images.html
而且另外一个具有几乎相同的code和我有一些问题,/在不一致的图像是如何在不同的设备进行处理。

我的code用于收集图像是这样的:

 私人无效init_phone_image_grid(){
    的String [] = IMG {MediaStore.Images.Thumbnails._ID};
    URI URI = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI;
    imagecursor = managedQuery(URI,IMG,空,
            空,MediaStore.Images.Thumbnails.IMAGE_ID);
    image_column_index = imagecursor
            .getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
    数= imagecursor.getCount();
    imagegrid =(GridView控件)findViewById(R.id.PhoneImageGrid);
    imagegrid.setAdapter(新ImageAdapter(getApplicationContext()));
    imagegrid.setOnItemClickListener(新OnItemClickListener(){
        @覆盖
        公共无效onItemClick(适配器视图父母,视图V,INT位置,
                长ID){
            System.gc()的;
            的String [] = PROJ {MediaStore.Images.Media.DATA};
            actualimagecursor = managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI,PROJ,
                    NULL,NULL,NULL);
            actual_image_column_index = actualimagecursor
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            actualimagecursor.moveToPosition(位置);
            串I = actualimagecursor
                    .getString(actual_image_column_index);
            System.gc()的;
            意向意图=新意图(getApplicationContext()
                    EvidenceImageView.class);
            intent.putExtra(文件名,我);
            startActivity(意向);
        }
    });
}

我运行的是Android 2.2的模拟器,并能创造一个SD卡文件,它安装..我复制了一些图像转换成使用亚行一个文件夹,重新启动仿真器(我的应用程序起初并不显示任何图像)。 。重启后一些图片在我的应用程序出现了但不是全部。然后当我打开自带的模拟器我能得到我的画廊来加载所有的图像蛮好的Gallery应用程序。但是我也有一个HTC thunberbolt,我已经得到了它的照片(在/ SD卡/ DCIM / 100MEDIA)
它根本不会在相同的应用程序(指一个我工作)显示任何图像。我没有手机迷上了电脑,所以我知道有我的电话能够没有问题访问SD卡。还我已经试过了我的电话,我的照片/视频负载只是细来到画廊应用..附带HTC手机的应用比自带的香草Android手机的一个有点不同我相信。这使我怀疑系统未移交的图像以同样的方式。

我是全新的Andr​​oid开发,并希望这将是pretty简单..我看着其他一些应用程序,如Facebook,它似乎把我直接进入由HTC提供的,当我想画廊上传照片。或许我可以采取同样的方法(不能完全确定如何)..
最后,我希望用户能够选择多张图片,并上传所有的人...
我还发现源$ C ​​$ C为内建Android相机应用:

<一个href=\"http://android.git.kernel.org/?p=platform/packages/apps/Camera.git;a=tree;f=src/com/android/camera;hb=1b53b364907b94c9cb0ba22b486aec4bf1ba7a7a\" rel=\"nofollow\">http://android.git.kernel.org/?p=platform/packages/apps/Camera.git;a=tree;f=src/com/android/camera;hb=1b53b364907b94c9cb0ba22b486aec4bf1ba7a7a

这是有些有用的,但相当多的信息,在这一点上消化。

的任何解释这个东西是如何工作将是巨大的。主要的事情虽然是,如何让我的画廊显示所有的缩略图(如果有必要创建缩略图)..或者,我怎么能与系统接口画廊..


解决方案

  

它似乎把我直接进入
  由HTC当我提供的图库
  要上传的照片。或许我
  可以采取同样的方法。


什么是错的:

<一个href=\"http://stackoverflow.com/questions/2507898/how-to-pick-a-image-from-gallery-sd-card-for-my-app-in-android\">how从画廊(SD卡)为我的Andr​​oid应用程序选择一个形象?

I've followed the tutorial here: http://androidsamples.blogspot.com/2009/06/how-to-display-thumbnails-of-images.html and also another one which has almost identical code, and I'm having some problems/inconsistencies in how images are processed on different devices.

My code for gathering the images is this:

private void init_phone_image_grid() {
    String[] img = { MediaStore.Images.Thumbnails._ID };
    Uri uri = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI;
    imagecursor = managedQuery(uri, img, null,
            null, MediaStore.Images.Thumbnails.IMAGE_ID);
    image_column_index = imagecursor
            .getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
    count = imagecursor.getCount();
    imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);
    imagegrid.setAdapter(new ImageAdapter(getApplicationContext()));
    imagegrid.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView parent, View v, int position,
                long id) {
            System.gc();
            String[] proj = { MediaStore.Images.Media.DATA };
            actualimagecursor = managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,
                    null, null, null);
            actual_image_column_index = actualimagecursor
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            actualimagecursor.moveToPosition(position);
            String i = actualimagecursor
                    .getString(actual_image_column_index);
            System.gc();
            Intent intent = new Intent(getApplicationContext(),
                    EvidenceImageView.class);
            intent.putExtra("filename", i);
            startActivity(intent);
        }
    });
}

I have an emulator running android 2.2 and was able to create an sdcard file to mount with it.. I copied some images into a folder using adb and restarted the emulator (my app didn't show any images at first).. After rebooting some of the images showed up in my app but not all.. Then after I open the Gallery application that comes with the emulator I was able to get my gallery to load all of the images just fine.. However I also have a HTC thunberbolt and i've got photos on it (under /sdcard/DCIM/100MEDIA) and it will not display any images at all in the same app (referring to the one I'm working on).. I do not have the phone hooked up to the computer so I know there is no problem with my phone being able to access the sdcard.. Also I've tried the gallery application that came with my phone and my photos/videos load just fine in that.. The application that comes with HTC phones is a bit different than the one that comes with vanilla android phones I believe.. This makes me wonder if the system isn't handing images the same way..

I am brand new to android development and was hoping this would be pretty simple.. I looked into some other apps, such as facebook, and it appears to take me directly into the gallery provided by htc when I want to upload a photo.. Perhaps I could take this same approach (not totally sure how).. Eventually I want the user to be able to select multiple images and upload all of them... I also found the source code for the Camera app that comes with android:

http://android.git.kernel.org/?p=platform/packages/apps/Camera.git;a=tree;f=src/com/android/camera;hb=1b53b364907b94c9cb0ba22b486aec4bf1ba7a7a

This is somewhat useful but quite a bit of information to digest at this point.

Any explanations of "how this stuff works" would be great. The main thing though is, how do I get my gallery to show all of the thumbnail images (creating thumbnails if necessary).. Or, how can I interface with the system gallery..

解决方案

it appears to take me directly into the gallery provided by htc when I want to upload a photo.. Perhaps I could take this same approach

What's wrong with this:

how to pick a image from gallery (SD Card) for my app in android?

这篇关于如何获得在Android设备上的所有图像(特别是SD卡)(2.1或更高)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆