How to check whether Google map add-on is available on the android real machine [reprinted] How to check whether Google map add-on exists on the android real machine

Source: Internet
Author: User
How can I check whether Google map add-on exists on the android real machine?

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-onProgram(That is<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 twoCodeBranch:
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:<Uses-library>The tag also contains an unpublished attribute"Android: Required", You canCom. Google. Android. MapsThis attribute of the library is set to false, that is:

<! -- 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:

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=NewIntent ();
Intent. setclass (mainactivity.This, Mymapactivity.Class);
Startactivity (intent );

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:<Uses-library>The tag also contains an unpublished attribute"Android: Required", You canCom. Google. Android. MapsThis attribute of the library is set to false, that is:

<! -- 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:

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=NewIntent ();
Intent. setclass (mainactivity.This, Mymapactivity.Class);
Startactivity (intent );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.