You generally don't need to use reflection for this.  That's a really
awkward way to do it...  just check the platform version number and only
call the API if it is >= the version where that API was introduced.

On Thu, Aug 2, 2012 at 7:45 AM, Jeremy Villalobos <
[email protected]> wrote:

> Yes
>
> Do note that some API calls will throw Exceptions on Froyo.  To avoid
> this, use Reflections
>
> For example: my app supports from Froyo upward, but Froyo does not support
> icons on the Preference Activity.  So I use this to set the icon for ICS,
> and skip the step on Froyo
>
>  void workAroundSetPicture(Preference pref, int resource){
>     try {
> Method m = pref.getClass().getMethod("setIcon", int.class);
>  m.invoke( pref,  resource );
> } catch (SecurityException e) {
> e.printStackTrace();
>  } catch (NoSuchMethodException e) {
> e.printStackTrace();
> } catch (IllegalArgumentException e) {
>  e.printStackTrace();
> } catch (IllegalAccessException e) {
> e.printStackTrace();
>  } catch (InvocationTargetException e) {
> e.printStackTrace();
> }
>     }
>
> The top right corner on the Android Developer documentation mentions for
> which Version the methods were introduced.
>
> On Wednesday, August 1, 2012 10:27:06 AM UTC-4, Eric oboite wrote:
>>
>> When creating my new app should I build against 2.2 or 4.1? I know 2.2
>> has 83% of the market right now but can I build against 4.1 and make the
>> min sdk android 2.0?
>>
>>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to