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

后端 未结 8 1008
别那么骄傲
别那么骄傲 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:28

    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:

    library:com.google.android.maps
    
    0 讨论(0)
  • 2020-12-02 16:29

    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="com.google.android.maps" />
    

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

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

    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

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

    This worked for me:

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

    Then check this out: http://android-developers.blogspot.com.ar/2009/01/can-i-use-this-intent.html

    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.

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

    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="com.google.android.maps" 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

    try{
         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.

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

    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);
        }
    }
    
    0 讨论(0)
提交回复
热议问题