如何找到联系人图像支持的最大图像尺寸? [英] How to find the max image size supported for contacts images?
问题描述
starting with jelly bean (4.1), android now supports contact images that are 720x720 .
之前,从ICS(4.0)开始,android已支持256x256 .
before, starting with ICS (4.0), android has supported contact images that are 256x256.
在此之前,联系人照片的大小仅为缩略图-96x96
and before that, contact photos had just a size of a thumbnail - 96x96
API中是否有任何函数可以返回联系人图像的最大大小?
is there any function in the API that returns the max size of the contact image?
我还希望制造商不要更改最大图像尺寸,即使他们做了并且我们有这样的功能,它也会为我们返回正确的尺寸.
i also hope that the manufacturers didn't change the max image sizes, and even if they did and we have such a function, it would return us the correct size.
推荐答案
according to this link, the correct way to get the max size is:
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static int getMaxContactPhotoSize(final Context context) {
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
// Note that this URI is safe to call on the UI thread.
final Uri uri = ContactsContract.DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI;
final String[] projection = new String[] { ContactsContract.DisplayPhoto.DISPLAY_MAX_DIM };
final Cursor c = context.getContentResolver().query(uri, projection, null, null, null);
try {
c.moveToFirst();
return c.getInt(0);
} finally {
c.close();
}
}
// fallback: 96x96 is the max contact photo size for pre-ICS versions
return 96;
}
如果我们至少使用API 16(4.1),则可以使用类似的内容:
if we use at least API 16 (4.1), it's possible to use something like:
@AnyThread
@RequiresPermission(anyOf = [Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS])
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
fun getMaxContactPhotoSize(context: Context): Int {
// Note that this URI is safe to call on the UI thread.
if (contactMaxPhotoSize > 0)
return contactMaxPhotoSize
val uri = ContactsContract.DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI
val projection = arrayOf(ContactsContract.DisplayPhoto.DISPLAY_MAX_DIM)
context.contentResolver.query(uri, projection, null, null, null)?.use { cursor ->
cursor.moveToFirst()
contactMaxPhotoSize = cursor.getInt(0)
}
if (contactMaxPhotoSize > 0)
return contactMaxPhotoSize
// fallback: 720x720 is the max contact photo size for 4.1 version
contactMaxPhotoSize = 720
return contactMaxPhotoSize
}
这篇关于如何找到联系人图像支持的最大图像尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!