1

I am making an app and the Google Maps API is a very depending part for me and I want to get a kind of light like this one: http://findicons.com/files/icons/1933/symbols/128/green_light.png And when the Google maps API is down it changes to a red version of that picture.

greetings

Rik Nijdeken
  • 49
  • 1
  • 7

2 Answers2

1

First of all, I think it's safe to assume the Google Maps API won't ever be down. But, to answer your question:

  1. Find the pictures you want to use
  2. Add them as drawables to your app project (java/res/drawable)
  3. Add ImageView to your layout
  4. Add the android:src attribute to your ImageView (in the layout's .xml)

Example:

<ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/service_online" />

You can also change the ImageView's image source programmatically, more information on that here.

Community
  • 1
  • 1
nbokmans
  • 5,492
  • 4
  • 35
  • 59
0

As others said, the Maps API should be present always, but anyway.. You can try to use any method from the API inside a try/catch block inside your app. A simple example:

mApiAvailable = true;
try {
    mMapsApi.checkVersion(); // I made up the method name
} catch (Exception ignored) {
    mApiAvailable = false;
}

Then for your ImageView (image names are also made up) set the appropriate icon:

mIndicator.setImageResource(mApiAvailable ? R.drawable.api_on : R.drawable.api_off);

You could listen for some location event if such event exists to check the availability again and update the ImageView.

milosmns
  • 3,595
  • 4
  • 36
  • 48