How to make maps work on old and new Apis at the same time?

Asked

Viewed 223 times

1

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

For now, I’ve given up on this.

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

The question arises from the impossibility of using fragments in version 2.2 and, from what I read, the Key API obtained from the current version’s Console API requires fragments.

How to get out of this problem?

1 answer

2

Android supports fragments in older versions (up to 1.6) as long as you replace the classes related to this feature with equivalent classes that are in the revision support library 4. 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, only the package name. Beware of Imports.

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

See details on this post.

  • Thank you, Piovezan.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.