On Sat, Aug 7, 2010 at 8:50 PM, skyhigh <[email protected]> wrote:
> However, I am having trouble trying to use reflection for the methods:
>
> requestAudioFocus
> abandonAudioFocus
>
> because these methods require an OnAudioFocusChangeListener parameter
> which is unknown on Android devices running 1.5 to 2.1.  Because the
> parameter type that must be passed into these methods is unknown and
> also because my application has to have an instance of the
> OnAudioFocusChangeListener object I am having trouble making
> reflection work.

Use conditional class loading instead. This blog post refers to it as
using a wrapper class:

http://developer.android.com/resources/articles/backward-compatibility.html

Here is a sample project demonstrating the concept with a somewhat
different implementation:

http://github.com/commonsguy/cw-advandroid/tree/master/Contacts/Spinners/

> I also
> can't figure out how to define my instance of
> OnAudioFocusChangeListener so that the application can be loaded on a
> device running Android 1.5 through 2.1 without getting a Force Close
> message while it is loading.

Just don't load the class that has the OnAudioFocusChangeListener
except on a 2.2 device. In other words, don't go down a code path that
refers to OnAudioFocusChangeListener, except on a 2.2 device.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books

-- 
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