LZN
LZN

Reputation: 315

How to develop an application which runs on Android devices with and without GMS included?

I want to develop an application which contains map features and runs on the Android OS. My question is how can this app run on Android devices without the Google maps library?

For example, there is an activity which contains some fragments, one of the fragment including the map feature. In this case, the activity 'MUST' extends MapActivity which is in maps library. This is no problem on devices with GMS, but how about devices without GMS ?

First, I add an attribute 'required="false"' for maps library in AndroidManifest.xml

<uses-library android:name="com.google.android.maps" 
    android:required="false"/>

And have the activity not use the map fragment if there is no maps library in device. But the activity extends MapActivity, and MapActivity is in the maps library. How can this activity extend MapActivity when the devices have the maps library and extend Activity when devices do not ?

Upvotes: 1

Views: 300

Answers (1)

Vasile Jureschi
Vasile Jureschi

Reputation: 2247

You could implement this by having two different classes one extending MapFragment, and one extending Fragment or Activity and then checking for the availability of Google Play Services.

If you plan on using Google Maps V2 (and you should since V1 will stop working in March) there is a way to check if Google Play services are available http://developer.android.com/google/play-services/setup.html

Once you have established if Google Play services are available you can either instantiate the activity that extends MapFragment or the one that extends Activity.

Of course the common functionality will be shared between classes, and in this case you will have to do it through composition since inheritance is unavailable.

Upvotes: 2

Related Questions