0

I am using Contacts.Photo.PHOTO column name of android.provider.ContactsContact.Contacts class to get photo of phone contact. Minimum sdk-version of my application is 10, so when using this constant it gives me warning of 'This API added in 11 (Current is min 10)'.
I check of Android docs and found that this Constant is added in API 11, but with great surprize it working well in devices having Android 2.3.6 (i.e. sdk 10).

How is that possible?

See my code:

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.

My min-sdkversion is 10 and target-sdkversion is 10.

This same thing is happening with Intents.Insert.DATA constant of android.provider.ContactsContact.Intents class

pratik03
  • 651
  • 2
  • 7
  • 23
  • `but with great surprize it working well in devices having Android 2.3.6 (i.e. sdk 10).` how do you know it is working well? because `cursor.getColumnName(0)` prints out the column name? – pskink Feb 19 '16 at 05:58
  • @pskink: check my edited code. – pratik03 Feb 19 '16 at 07:24
  • native's image is displayed in imageView object. – pratik03 Feb 19 '16 at 07:26
  • see [here](http://androidxref.com/6.0.1_r10/xref/frameworks/base/core/java/android/provider/ContactsContract.java#2000) on how you should access your `Uri` (line 2020) – pskink Feb 19 '16 at 08:42

1 Answers1

0

Eclipse highlights warnings/errors. It also highlights its possible solutions too. That's very good thing for developer.
From there I cam to know that when application is building to support API 10 onwards and if any API(rather constant) is not available in API level 10, then that constant value is hard-coded inserted in code. So, apk itself generated with that hard-coded constant for every API level. No referencing shall be performed then.
Same thing is happening with Contacts.Photo.PHOTO API.

You can also try in your code. Use above API keeping min sdk version 10 and target sdk version as per your like.

pratik03
  • 651
  • 2
  • 7
  • 23