首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Contacts.Photo.PHOTO常量在API10中工作正常

Contacts.Photo.PHOTO常量在API10中工作正常
EN

Stack Overflow用户
提问于 2016-02-19 13:53:10
回答 1查看 39关注 0票数 0

我正在使用android.provider.ContactsContact.Contacts类的Contacts.Photo.PHOTO列名来获取电话联系人的照片。我的应用程序的最低sdk版本是10,所以当使用这个常量时,它会给我警告‘这个API在11中添加(当前是最小的10)’。

我查看了Android文档,发现API 11中添加了这个常量,但令人惊讶的是,它在安装了Android 2.3.6 (即sdk 10)的设备上工作得很好。

那件事怎么可能?

请看我的代码:

代码语言:javascript
复制
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, someContactId);
Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
Cursor cursor = getContentResolver().query(photoUri, new String[] {Contacts.Photo.PHOTO}, null, null, null);

Log.d(null, cursor.getColumnName(0)); //This returns 'data15' column.

cursor.moveToFirst(); // considering cursor is not null
Byte[] data = cursor.getBlob(0);
InputSteam inputStream = new ByteArrayInputStream(data);
Bitmap bitmapImage = BitmapFactory.decodeStream(inputStream);
imageView.setImageBitmap(bitmapImage); //imageView is of ImageView object i.e. displayed in view.

我的min-min版本是10,target-min版本是10。

android.provider.ContactsContact.Intents类的Intents.Insert.DATA常量也发生了同样的事情

EN

回答 1

Stack Overflow用户

发布于 2016-03-09 17:59:45

Eclipse突出显示警告/错误。它还强调了其可能的解决方案。这对开发者来说是一件非常好的事情。

从那里我可以知道,当应用程序正在构建以支持API 10之后,并且如果在API级别10中没有任何API(相当于常量),那么该常量值被硬编码插入到代码中。因此,apk本身为每个API级别生成了硬编码常量。此时不应执行引用。

同样的事情也发生在Contacts.Photo.PHOTO API上。

您也可以在您的代码中尝试。请根据您的喜好使用以上API,最小sdk版本10和目标sdk版本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35498252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档