How can I detect pogrammatically whether a Google Map was actually loaded on Android with API v2 (e.g. when network is not available)? -
i have google map api v2 working fine on android using supportmapfragment in fragmentactivity.
however, when there no network connection (and no cached information), obviously, no map can shown. logcat gives me error message confirming ("google maps android api: failed load map. not connect google servers"), not thrown.
how can detect case programmatically, because forward different activity in case? docs claim if no map loaded getmap() called on supportmapfragment return null, not seem case.
i've been searching around 2 days solution, not able find anything. totally overlooking or not possible find out whether actualy loaded? appreciated.
edit:
here current code, error message appears on logs after setcontentview executed (checked debugger), still says connectionresult == sucess.
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); supportmapfragment smf = ((supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map)); map = smf.getmap(); if (map != null && googleplayservicesutil.isgoogleplayservicesavailable(this) == connectionresult.success) { // dosomething map } else { toast.maketext(this, "google maps not working", toast.length_short).show(); system.out.println(googleplayservicesutil.isgoogleplayservicesavailable(this)); // forward activity } }
googleplayservicesutil.isgoogleplayservicesavailable related googleplayservices.apk available on device. api not give indication of when tiles loaded.
you have options to:
- check if tiles cached trying (hackish, simplified):
new file(getexternalcachedir(), "cache_vts_your.package.name.0").exists() - check internet availability own code
parse logcat find error
edit:
note point 3 deprecated because applications not allowed read logs anymore due security reasons
Comments
Post a Comment