Using new sdk methods on devices running older sdks?

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

Sponsored Links

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

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

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

  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?



Other Threads

1. setImageViewResource not working

I have a simple widget (whose entire layout is just an ImageView) that
starts and stops a service. From within the service, I'd like to
switch the image displayed by such ImageView.
So, i did this:

public int onStartCommand(Intent intent, int flags, int startId){
        RemoteViews remoteViews = new RemoteViews(getPackageName(),
        remoteViews.setImageViewResource(, R.drawable.image1);


        return START_STICKY;


public void onDestroy(){
        RemoteViews remoteViews = new RemoteViews(getPackageName(),


But it doesn't work.  onStartCommand and onDestroy are called, but the
image doesn't change.
What gives?


2. After onActivityResult event State Is Gone (Droid Phones)

I have a problem that's only affecting Droid phones. I end up not
being able to access global variables after an onActivityResult event.

While looking into this I came across:

I follow those directions, but still the value is NULL.

On my HTC Hero everything I've tried works. On Droid phones everything
is NULL or an empty string.

What I need is the URL from the webview. In the onPageFinished I've
been putting the URL into a global variable. The app has the correct
URL in that method because that's when I pop open the imagepicker.
After that is when the global variable value is gone. I also can't
read the webview (I can on my Hero, can't on Droid's) after hitting
the onActivityResult event. GetUrl() returns NULL for them, works fine
for me. Everything also works fine in the simulator. I've 1.5, 2.1,
and 2.2 in the simulator.

How else can I store the info I need to retrieve?


3. File extensions and MIME type

4. is there a way to make drawable clickable?

5. Debugging Droid X-specific issues

6. Widget Configuration Activity issue

7. Problem figuring out how USB mass storage works in Android