Check BitmapDescriptor for null

I want to check BitmapDescriptor for null.

The documentation for BitmapDescriptorFactory.fromAsset states that:

Returns a BitmapDescriptor that was loaded from the asset, or null if it failed to load.

BitmapDescriptor bd = BitmapDescriptorFactory.fromAsset("markerimages/filename.png"); if (bd == null) { // doSomething... } 

Despite this, I can not catch BitMapDescriptor in the zero state - even when I pass the name of a file that does not exist, the fromAsset method does not return zero.

+7
java android google-maps-android-api-2
source share
2 answers

The fromAsset method may not return null, but it may return the same as defaultMarker (). (i.e. documentation is not true)

I would check if the value you get for the (supposedly non-existent) asset is either '==' or .Equals defaultMarker (). This may be how you discover a non-existent asset.

+1
source share

I found that, unlike the documentation, BitmapDescriptorFactory.fromAsset (String) does not return null if the specified asset does not exist. I am currently doing work where I preload the list of assets that exist using AssetManager.list (""). Then, for the asset name in question, I look at the cached list of assets to determine if the specified asset exists.

This was the least resource-intensive approach I could use, since I could not depend on zero return when the resource did not exist.

0
source share

All Articles