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. ImageView hardcoded into layout referencing drawable resources

If I reference a drawable in the "drawable" directory, I see the image
in my layout, but if I reference a drawable in the "drawable-hdpi"
directory, I don't see it (but I don't get an error of any sort
either).  I want to include the app icon on the splash screen, and
would prefer to use the high-res icon.

This works:
                        <ImageView
                                android:layout_width="wrap_content"
android:layout_height="wrap_content"
                                android:layout_gravity="center" 
android:layout_marginRight="20dip"
                                android:src="@drawable/app_icon" />

This doesn't:
                        <ImageView
                                android:layout_width="wrap_content"
android:layout_height="wrap_content"
                                android:layout_gravity="center" 
android:layout_marginRight="20dip"
                                android:src="@drawable-hdpi/app_icon" />

Thoughts?

-- 

2. OOT : Hollywood Stop Edarkan Produksi Filmnya ke Indonesia

Sorry kalo OOT. Haduh2 makin ribet amat sih pemerintah sekarang, abis
urusan BB, sekarang soal pajak film ditambahin

http://movie.detikhot.com/read/2011/02/18/211838/1574077/229/hollywood-stop-edarkan-produksi-filmnya-ke-indonesia

-- 
===============

3. drawBitmapMesh

4. Android SDK and AVD Manager shows already installed updates as "Available"

5. Perkenalan anggota baru

6. Significant Fragment bug? onInflate() not called at the right time on a restart

7. MarkerManager for Android