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

后端 未结 8 1009
别那么骄傲
别那么骄傲 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.

    0 讨论(0)
  • 2020-12-02 16:55

    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.

    0 讨论(0)
提交回复
热议问题