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

后端 未结 8 1140
别那么骄傲
别那么骄傲 2020-12-02 16:21

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 i

8条回答
  •  不知归路
    2020-12-02 16:52

    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.

提交回复
热议问题