Using new sdk methods on devices running older sdks?

by Mark Wyszomierski » Tue, 22 Dec 2009 01:27:52 GMT


Sponsored Links
 Hi,

I'm using the level 5 sdk to compile my app, but set my target to sdk
level 3 in my manifest. All is fine.

I may need to use some level 5 classes (ExifInterface) though. What's
the right way to go about using them while not fouling things up for
devices running older sdk versions? Do we simply restrict use of the
newer API methods to completely separate class files? Something like
this:

  // Test.java
  class Test
  {
      public boolean sdkDependentItem() {
          if (Build.VERSION.SDK.equals("5")) {
              return (new sdk5()).getItem();
          }
          else {
              return (new sdk3and4()).getItem();
          }
      }
   }

  // sdk5.java
  class sdk5 {
      public boolean getItem() {
          // can use sdk level 5 apis in here ok.
      }
  }

  // sdk3and4.java
  class sdk3and4 {
      public boolean getItem() {
          // can use sdk level 3 and 4 apis in here ok.
      }
  }

so as long as the api methods are completely separated into files that
the older devices won't invoke, we should be ok?

Thanks

--



Other Threads

1. How to use onListItemClick() while overriding dispatchTouchEvent() in ListActivity?

Hi, I have a class extending ListActivity, and I want to catch
touchevent on it so I override dispatchTouchEvent.

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
  ...
}

And since it's a ListActivity, of cource I want to override the
onListItemClick(), too:
@Override
protected void onListItemClick(ListView l, View v, int position, long
id) {
  ...
}

But now I find that the dispatchTouchEvent() will intercept ALL touch
event on the activity, so onListItemClick() will never be called.
I tried
 super.dispatchTouchEvent(ev);
but it does not work.

Anyone has any idea for this? Thanks!

--~--~---------~--~----~------------~-------~--~----~

2. How to launch the street view from map view

New to android, please forgive if this question sounds naive.

The latest MapView can check whether the map is in street view mode
and allow users to toggle it.

However, the set street view api only display the blue layout on top
of the map. Is there any way that I can launch the street view like in
Google Map.

Also, does this version support route and direction?

Please kindly advice. Thanks

--~--~---------~--~----~------------~-------~--~----~

3. listActivity and checkBox

4. About the use of the Wi-Fi function

5. Images and Layout Questions

6. how to get access to private API s

7. EventHandler ?