首页 / 操作系统 / Linux / Android从图库(Gallery)选择一张图片
在Android编程中,有时我们可能会有这样的需求,从图库里选择一张图片作为头像这时,我们就需要从我们的应用中去激活系统的图库应用,并选择一张图片这个接口Android已经为我们提供我们先来看一下android图库的系统源码,打开android源码_homepackagesapps,在里边我们找到gallery文件夹,即为图库的源码打开后,我们先打开清单文件,在里边找到这样一段代码<activity android:name="com.android.camera.ImageGallery"
android:label="@string/gallery_label"
android:configChanges="orientation|keyboardHidden"
android:icon="@drawable/ic_launcher_gallery">
.......
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
</intent-filter>
.......
</activity>从上边的意图过滤器我们可以发现,我们可以通过一个叫android.intent.action.PICK的action来激活图库并选择图片或是视频 为了知道图库应用给我们返回的key值是什么,我们还需到com.android.camera.ImageGallery类去看一下源码在src目录下找到该类并打开,我们在里边搜“setResult”关键字,我们发现这样一段代码else {
Intent result = new Intent(null, img.fullSizeImageUri());
if (myExtras != null && myExtras.getBoolean("return-data")) {
// The size of a transaction should be below 100K.
Bitmap bitmap = img.fullSizeBitmap(
IImage.UNCONSTRAINED, 100 * 1024);
if (bitmap != null) {
result.putExtra("data", bitmap);
}
}
setResult(RESULT_OK, result);
finish();更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2013-11/93149p2.htm相关阅读:Android开发之简单图片浏览器 读取SDCard图片+形成缩略图+Gallery http://www.linuxidc.com/Linux/2012-12/77110.htmAndroid Gallery 3D效果 http://www.linuxidc.com/Linux/2013-04/83246.htmAndroid中的GalleryView实例演示 http://www.linuxidc.com/Linux/2013-07/87060.htm