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
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().
Google Maps is pre-installed on just about every current version of 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).
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);
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With