Not all Android real machines contain Google Map add-on. To build Google Map add-on, you need to discuss it with google.
However, if we develop an Android application that uses Google Map add-on (<uses-library android: name = "com. google. android. maps "/>), you will find that this program cannot be successfully installed on a real machine without a built-in Google Map add-on. So what can we do to solve this problem?
There are two methods:
1) maintain two code branches:
One branch is for Android real machines with built-in Google Map add-on, and the other branch is for Android real machines without built-in Google Map add-on.
However, this will increase the maintenance cost, and careless users may install mismatched branches on their own machines, thus reducing the software friendliness.
2) keep only one code Branch:
A foreign Daniel pointed out that the <uses-library> tag also contains an unpublished attribute "android: required". You can. google. android. this attribute of the maps library is set to false, that is:
Java code
<! -- The "android: required" attribute was added in API level 5 (Android 2.0) -->
<Uses-library android: name = "com. google. android. maps" android: required = "false"/>
This means that if Google Map add-on is built on the target machine, the application can be used normally. If Google Map add-on is not built on the target machine, the application can be installed successfully. However, developers need to determine whether Google Map add-on is available in the code, for example:
Java code
Try {
Class. forName ("com. google. android. maps. MapActivity ");
} Catch (Exception e ){
Toast. makeText (MainActivity. this, "Oop! Google map unavailable ", Toast. LENGTH_SHORT). show ();
Return;
}
Intent intent = new Intent ();
Intent. setClass (MainActivity. this, MyMapActivity. class );
StartActivity (intent );
Author "multiarrow"