How to detect an android device whether it supports google maps API-ThrowExceptions

Exception or error:

I am currently developing an android application uses Google map API.

I am wondering do all android devices support map API, becuase this api is an optinal api and it is an add-on to the platform.

I am worried that my application won’t be able to run on that device.

What I need to know is programatically detect wether the device support map API, and catch the exception and do something else.

Because, using map capability is only one of features of my application, I would like to let those devices that don’t support map api can still download and run my application with out effecting other features of my app.

Any comment or suggestions are welcome

How to solve:

I have used following solution in addition to described

<uses-library android:name="" android:required="false"/>

in another answers:

public void mapClick(View view)
        // check if Google Maps is supported on given device

        this.startActivity(new Intent(this, MyMapActivity.class));
    catch (Exception e)
        UIUtils.showAlert(this, R.string.google_maps_not_found);


I needed to see if the library existed before attempting any calling, so I could fill the relevant preferences before-hand. Here’s the code I came up with to check.

public static boolean hasSystemSharedLibraryInstalled(Context ctx,
        String libraryName) {
    boolean hasLibraryInstalled = false;
    if (!TextUtils.isEmpty(libraryName)) {
        String[] installedLibraries = ctx.getPackageManager()
        if (installedLibraries != null) {
            for (String s : installedLibraries) {
                if (libraryName.equals(s)) {
                    hasLibraryInstalled = true;
    return hasLibraryInstalled;

And then I check to see if is installed.


Thanks for all your guys help! all of your suggestion are useful to me!!

I wrote a simple application that is able to deployed on None-Google-Map API emulator, and detect presence of Google API problematically.

What I did was I specifying <uses-library android:name="" android:required="false" />

(but android “required” attribute only works for 2.1 and doesn’t work for 1.6. I will need to find out why. cos when I had look at the documentation, it says that this attributed supported by 1.6)

Thus, I am able to deploy the application on to emulator.

Secondly, I created a map activity which is called HelloMaps
In my main activity

     mapActivity = new Intent(TestApp.this, HelloMaps.class); 
     startActivityForResult(mapActivity, 0); 
}catch(NoClassDefFoundError e){
(Toast.makeText(TestApp.this, "Google Map API not found", Toast.LENGTH_LONG)).show(); 

This will catch the exception and tell me that the device couldn’t run map activity.


You are right, some Devices, like Archos 5IT and Some Tablet does not have Google Maps, Android Market, etc…

Here is my Code.
BelgianMap is a MapActivity:

try {
    Intent i = new Intent(InfoGare.this, BelgianMap.class);
    startActivityForResult(i, 0);
catch(ActivityNotFoundException e) {
    Toast.makeText(context, "Google Map not found", Toast.LENGTH_LONG).show();

But maybe there is an other way to find that at the creation of your application and display a message. That might be better.


This worked for me:

Use the (undocumented?) uses-library android:name=”” android:required=”false” in the manifest. This will allow installation in a maps-api non-supported device.

Then check this out:

You can still have all your maps-api code intact in the app (no need for 2 versions), just code your UI to prevent running it. (In my case I greyed-out a preference). As noted, technique outlined above effectively predicts something that won’t work, and allows you to respond (no FCs), instead of just reacting to a problem.


The optional API just applies to the emulator as far as I know. The 2 different version of the API levels is only for the emulator, real devices should all have the maps API I think


If you are using googlemaps in your application you should include the following in your manifest.xml inside the application tags

 <uses-library android:name="" />

This will either prevent a user from installing your application or seeing it in the market, not sure which, maybe both.


By using adb, To prints all system libraries:

adb shell cmd package list libraries

If your device supports Google Maps, you’ll see this line:

Leave a Reply

Your email address will not be published. Required fields are marked *