设为首页 加入收藏

TOP

Android从图库(Gallery)选择一张图片
2014-11-24 02:29:30 来源: 作者: 【 】 浏览:1
Tags:Android 图库 Gallery 选择 图片

这时,我们就需要从我们的应用中去激活系统的图库应用,并选择一张图片


这个接口Android已经为我们提供


我们先来看一下android图库的系统源码,打开android源码_home\packages\apps,在里边我们找到gallery文件夹,即为图库的源码


打开后,我们先打开清单文件,在里边找到这样一段代码


android:label="@string/gallery_label"
android:configChanges="orientation|keyboardHidden"
android:icon="@drawable/ic_launcher_gallery">
.......






.......


从上边的意图过滤器我们可以发现,我们可以通过一个叫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();


相关阅读:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android通过服务实现消息推送 下一篇Java实现根据前序遍历构建二叉树..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: