How to make maps work in old and new APIs at the same time?

1

I've been struggling for over a month to run a simple app that shows a map. I managed, according to another post, to work in version 3.2, but not in 4.1 and, by friends' comments, this should be because of the hardware of the 4.1 tablet than a problem of the application itself.

For the time being, I gave up on this.

I have another question: how to make Google Maps work in both version 3.2 (that works) and version 2.2?

The question arises from the inability to use fragments in version 2.2 and, therefore, the API Key obtained from the API Console of the current version requires fragments.

How do you get out of this problem?

    
asked by anonymous 06.02.2014 / 11:07

1 answer

2
Android supports fragments in older versions (up to 1.6) as long as you replace the classes related to this functionality by equivalent classes that are in the revision 4 support library. To use these classes, you need to include the .jar of that library in the classpath of your project. This .jar is in {diretório_do_android}\sdk\extras\android\support\v4\android-support-v4.jar .

See which classes you should replace:

android.app.Fragment --> android.support.v4.app.Fragment
android.app.Activity --> android.support.v4.app.FragmentActivity
android.app.FragmentManager --> android.support.v4.app.SupportFragmentManager
com.google.android.gms.maps.MapFragment --> com.google.android.gms.maps.SupportMapFragment

Note that in the case of Fragment the class name has not changed, just the package name. Beware of imports.

Your Activity should then extend from FragmentActivity , within it you should call getFragmentSupportManager() instead of getFragmentManager() and you should replace the other classes with the corresponding versions.

See details on this post .

    
06.02.2014 / 11:42