Because KMZ is zipped KML you should unzip .kmz file to .kml before reading data or use ZipInputStream instead of FileInputStream like in this createLayerFromKmz() method:
private KmlLayer createLayerFromKmz(String kmzFileName) {
KmlLayer kmlLayer = null;
InputStream inputStream;
ZipInputStream zipInputStream;
try {
inputStream = new FileInputStream(kmzFileName);
zipInputStream = new ZipInputStream(new BufferedInputStream(inputStream));
ZipEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
if (!zipEntry.isDirectory()) {
String fileName = zipEntry.getName();
if (fileName.endsWith(".kml")) {
kmlLayer = new KmlLayer(mGoogleMap, zipInputStream, getApplicationContext());
}
}
zipInputStream.closeEntry();
}
zipInputStream.close();
}
catch(IOException e)
{
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
return kmlLayer;
}
And you can use it e.g. this way:
@Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
// path to your kmz file
String kmzFileName = Environment.getExternalStorageDirectory() + "/KMZ/markers.kmz";
try {
KmlLayer kmlLayer = createFromKmz(kmzFileName);
kmlLayer.addLayerToMap();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
}
NB! createLayerFromKmz() works only on "flat" KMZ structure.