How to install an application with mapactivity on a real machine that does not support Google map add-on

Source: Internet
Author: User

Not all android real machines contain Google map add-on.

If we develop an android application that uses Google map add-on ),

You will find that this program cannot be successfully installed on a real machine without the built-in Google map add-on.

Applications cannot be installed, which is a tough problem.

At least tell the user why not install it.

The following is a solution: (not the best. The best thing is that if Google map is not found in the real machine, I will add it to the program !)

There are two methods:

1) maintain two code branches:

One branch is for Android real machines with built-in Google map add-on,

The other branch is an android real machine with no built-in Google map add-on.

However, this will increase maintenance costs, and careless users may install mismatched branches on their own machines,

This reduces the software friendliness.

2) keep only one code Branch:

A foreign Daniel pointed out that the tag also contains an unpublished attribute "Android: required ",

You can set this attribute of the COM. Google. Android. Maps library 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 into the target machine,

The application can be used normally;

If the target machine does not have a built-in Google map add-on, you can also install the application.

However, developers must determine whether Google map add-on is available in the code,

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 = new intent ();

Intent. setclass (mainactivity. This, mymapactivity. Class );

Startactivity (intent );

Reference website:

[1] http://stackoverflow.com/questions/3909903/disable-mapview-if-it-is-not-supported

[2] http://androidforums.com/application-development/140147-does-all-android-devices-support-map-api.html

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.