Android SDK 100.6 - Issue loading maps

2837
7
Jump to solution
12-02-2019 08:39 AM
OscarDiago_Alonso
New Contributor III

Hi!

I'm migrating an old android application to the Android SDK 100.6. I am having a lot of trouble to display a map. I always get a blank screen.

All the examples I have found have the MapView in an Activity. In my application, the MapView is in a Fragment, but I don't think that is the issue.

My XML:

<com.esri.arcgisruntime.mapping.view.MapView
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
</com.esri.arcgisruntime.mapping.view.MapView>

My Fragment:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		myFragmentView = inflater.inflate(R.layout.home_view_tab_my_statistics,
				container, false);

		mMapView = (MapView) myFragmentView.findViewById(R.id.map);
		ArcGISMap map = new ArcGISMap("https://www.arcgis.com/home/webmap/viewer.html?webmap=65087932bac7461892b0d31f563a8c4d");

		map.addLoadStatusChangedListener(new LoadStatusChangedListener() {
			@Override
			public void loadStatusChanged(LoadStatusChangedEvent loadStatusChangedEvent) {
				String mapLoadStatus;
				mapLoadStatus = loadStatusChangedEvent.getNewLoadStatus().name();
				// map load status can be any of LOADING, FAILED_TO_LOAD, NOT_LOADED or LOADED

				if (mapLoadStatus == "LOADED") {
					mMapView.setViewpoint(new Viewpoint(Constants.MAP_DEFAULT_ENVELOPE_HOME));
				}
			}
		});
   mMapView.setMap(map);

		
   return myFragmentView;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The first mapLoadStatus is "LOADING", but the next one is always "FAILED_TO_LOAD".

Instead of using a webmap URL, I have tried with a map I have found in the ESRI Documentation; but the result is the same.

Basemap.Type basemapType = Basemap.Type.STREETS_VECTOR;
double latitude = 34.09042;
double longitude = -118.71511;
int levelOfDetail = 11;
ArcGISMap map = new ArcGISMap(basemapType, latitude, longitude, levelOfDetail);

Does anyone know what I am doing wrong? I'm stuck with this error.

Thanks for any help provided!

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi Oscar,

A couple possible things to make sure of:

Have you requested internet permissions in the AndroidManifest?

Try using the Portal API and with it the DefaultAuthenticationChallengeHandler in case there are credential issues.

Finally, take a look at the load errors in an else after you check if LOADED. Something like:

} else {
String error = "Portal item failed to load: " + portalItem.getLoadError().getMessage();
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
Log.e(TAG, error);

}

This sample might help with using Webmaps and the Portal API

View solution in original post

7 Replies
by Anonymous User
Not applicable

Hi Oscar,

A couple possible things to make sure of:

Have you requested internet permissions in the AndroidManifest?

Try using the Portal API and with it the DefaultAuthenticationChallengeHandler in case there are credential issues.

Finally, take a look at the load errors in an else after you check if LOADED. Something like:

} else {
String error = "Portal item failed to load: " + portalItem.getLoadError().getMessage();
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
Log.e(TAG, error);

}

This sample might help with using Webmaps and the Portal API

OscarDiago_Alonso
New Contributor III

Thanks for your answer!

My AndroidManifest already has that permission and the map I'm trying to use is 100% public. It worked OK with the 10.2.8 SDK (yes, I'm facing a huge leap forward in SDK versions).

I'm not sure about using the Portal API. The map is stored in ArcGIS Online (I guess it could be the same). The following implementaion would be correct for my map?

https://www.arcgis.com/home/webmap/viewer.html?webmap=65087932bac7461892b0d31f563a8c4d 

Portal portal = new Portal("http://www.arcgis.com");‍

PortalItem mapPortalItem = new PortalItem(portal, "65087932bac7461892b0d31f563a8c4d");

ArcGISMap map = new ArcGISMap(mapPortalItem);

‍‍‍‍‍‍

Could the build configuration be related with my issue?

android {
    compileSdkVersion 19
    buildToolsVersion '28.0.3'

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 19
    }

    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    api project(':showcase')
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.esri.arcgisruntime:arcgis-android:100.6.0'
}
0 Kudos
by Anonymous User
Not applicable

Hi Oscar,

The use of the portal api looks right to me and I can get the map to load with:

mMapView = (MapView) findViewById(R.id.mapView);
// create a map with the BasemapType topographic
Portal portal = new Portal("http://www.arcgis.com");
PortalItem portalItem = new PortalItem(portal, "65087932bac7461892b0d31f563a8c4d");
ArcGISMap map = new ArcGISMap(portalItem);
// set the map to be displayed in this view
mMapView.setMap(map);

Are you getting any load errors from the portal or the map? 

The one thing that looks odd to me in the build config is that you're targeting and compiling for such a narrow range of Android API. Are you sure your device is Android 19 or should you broaden the SDK version to say target 28 and compile 28 (leave the min as it is)?

Cheers,

Trevor

OscarDiago_Alonso
New Contributor III

This is the error I get with the steps you have described:

javax.net.ssl.SSLException: SSL handshake aborted: 
ssl=0x66396aa8: I/O error during system call, Connection reset by peer‍

I don't understand what it means...

0 Kudos
by Anonymous User
Not applicable

Sorry Oscar, I'd need to see more of the code--maybe make sure you're using a secure version of the portal link?

Portal portal = new Portal("https://www.arcgis.com");

The code above works on my device (API 29)

0 Kudos
OscarDiago_Alonso
New Contributor III

Thanks for your help! I already tried that.

The class doesn't have much else, except a couple of buttons.

I will try compiling the code with a newer Android version.

0 Kudos
OscarDiago_Alonso
New Contributor III

The problem was the tablet I was using to debug the application (Android 4.4)

I have tested the map loading with an Android 8.1 device and it is working.

Thanks!

0 Kudos