tags:

views:

97

answers:

5

Hi,

Hi all,

I am currently developing an android application uses Google map API.

I am wondering does all android devices support map API, becuase this api is an optianal 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 doesn't support map api are still able to download and run my application with out effecting other features of my app.

Any comment or suggestions are welcom

A: 

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

Falmarri
No.. For instance, the Archos 5IT (or some other tablets) does not Have Google Maps ( and does not Have Android Matket neither).
Profete162
Yes. some tablets doesn't have Google Maps. I tested on a real tablet device, when I install my map activity, it gives me install failed error message.
TS.xy
A: 

You are right, some Devices, like Archos 5IT and Some Tablet does not have Google Maps, Android Market, etc...

Here is my Code. BelgianMap is a MapActivity:

            try {
                Intent i = new Intent(InfoGare.this, BelgianMap.class);
                startActivityForResult(i, 0);
            }catch(ActivityNotFoundException e) {
                (Toast.makeText(context, "Google Map not found", Toast.LENGTH_LONG)).show();
            }

But maybe there is an other way to find that at the creation of your application and display a message. That might be better.

Profete162
This will work and has good redundancy. However if you simply don't want the users to be able to use the app then the solution I posted may be more fitting, and I think it is essential if you are using the googlemaps API.
stealthcopter
You are right! Thank a lot for the information, that will help me a lot!
Profete162
@Profete162 , Thanks very much. your code works for me. but I need to catch NoClassDefFoundError instead .
TS.xy
A: 

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.

stealthcopter
Yes, you are right. The Android market would filter out the app for the user. However, I would like to allow user to download my app not only from market but from my site. Because, using map capability is only one of features of my application, I would like to let those devices that doesn't support map api are still able to download and run my application with out effecting other features of my app.
TS.xy
use android:required="false"
hackbod
android :required = "false" helped me to installed my map application onto an none-google api supported emulator (2.1), at least I didn't get "Missing shared library" error message. However, this attribute doesn't work for 1.6 by some how, I coudn't compile, I am getting "No resouce identifier found for 'required' error message when I am compling project
TS.xy
To bypass the compilation error you could raise the target version to 2.1 and then set minsdkversion to 4. This would make it compile but 1.6 and below will ignore the required=false (I think)
stealthcopter
Yes!! if I do so, it allows me to compile, but 1.6 still ignore the required = false, and give me "Missing shared library" error message. See another post of mine http://stackoverflow.com/questions/3436674/uses-library-in-androidmanifest-xml
TS.xy
A: 

Assuming that the Google Maps API is a package, this is another way of detecting it:

try {
    this.getPackageManager().getPackageInfo("com.google.android.maps", 0);
    text += "It exists!\n";
} catch (NameNotFoundException e) {
    text += "Google Maps isn't installed... \n";
    e.printStackTrace();
}
skyuzo
That is NOT the Google maps API. That is the Google Maps library, and the fact that one of them exists has no bearing on the other.
hackbod
Ah, my bad. Should've researched more first.
skyuzo
A: 

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 is I specified 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.

TS.xy