Thanks Mark... I've had a quick stab but I'm missing something...
Class clazz=Class.forName("android.util.DisplayMetrics");
screenDensity = (Integer)clazz.getField("densityDpi").get(clazz);
"object is not an instance of the class"
The error makes sense but I'm not sure how to correct it...
On Dec 17, 12:18 pm, Mark Murphy <[email protected]> wrote:
> On Fri, Dec 17, 2010 at 7:10 AM, Neilz <[email protected]> wrote:
> > Hi all. The examples at...
>
> >http://android-developers.blogspot.com/2009/04/backward-compatibility...
>
> > ...show some good ideas of testing methods against incompatible
> > versions.
>
> > But the method I want to call is DisplayMetrics.densityDpi(); (since
> > level 4) which returns an int value. None of these examples return any
> > values, they're all void.
>
> The second half of that post returns an int from doStuff() in both
> NewClass and the WrapNewClass wrapper.
>
> However, densityDpi is a field, not a method, on DisplayMetrics. For
> that, you could just use reflection. Here is an example of using
> reflection to conditionally access a field (albeit a static data
> member, not an instance data member):
>
> https://github.com/commonsguy/cw-advandroid/tree/master/Contacts/Pick
>
> --
> Mark Murphy (a Commons
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> _The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
> Available!
--
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