Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 317
TS.xy Avatar asked Aug 04 '10 22:08

TS.xy


People also ask

How do I know if Google Maps is ready on Android?

This method can be called from both the onCreate() and onResume() stages to ensure that the map is always available. private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { mMap = ((MapFragment) getFragmentManager().

Do all Android phones have Google Maps?

Google Maps is pre-installed on just about every current version of Android.

Is Google Maps API free for Android?

You won't be charged until your usage exceeds $200 in a month. Note that the Maps Embed API, Maps SDK for Android, and Maps SDK for iOS currently have no usage limits and are at no charge (usage of the API or SDKs is not applied against your $200 monthly credit).


2 Answers

I have used following solution in addition to described

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

in another answers:

public void mapClick(View view)
{
    try
    {
        // check if Google Maps is supported on given device
        Class.forName("com.google.android.maps.MapActivity");

        this.startActivity(new Intent(this, MyMapActivity.class));
    }
    catch (Exception e)
    {
        e.printStackTrace();
        UIUtils.showAlert(this, R.string.google_maps_not_found);
    }
}
like image 194
Taras Avatar answered Sep 23 '22 06:09

Taras


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()
                .getSystemSharedLibraryNames();
        if (installedLibraries != null) {
            for (String s : installedLibraries) {
                if (libraryName.equals(s)) {
                    hasLibraryInstalled = true;
                    break;
                }
            }
        }
    }
    return hasLibraryInstalled;
}

And then I check to see if com.google.android.maps is installed.

like image 43
Jeff Avatar answered Sep 23 '22 06:09

Jeff