Select to view content in your preferred language

Blank MapView when I start the map without WiFi

3683
13
Jump to solution
10-21-2016 05:25 AM
JasonChristian
Emerging Contributor

Hi, I am currently building an Android App using ArcGIS runtime SDK for Android. The app has a MapView on the layout and I plan to make it work offline without wifi. Thus, I have provided myself several .tpk files as offline areas. Under working WiFi connection, it worked well (the map is displayed, along with the offline tiles). But, when I turned off the WiFi and restarted the app, it only shows blank (black) map

I used the OnStatusChangedListener to listen to the MapView status. Here is the code snippet

mapView.setOnStatusChangedListener(new OnStatusChangedListener() {
    @Override
    public void onStatusChanged(Object o, STATUS status) {
        //initialization
        if (o == mapView && status == STATUS.INITIALIZED){
            //setup everything, including adding offline maps here
            //...

I was under impression that the INITIALIZED status requires connecting to the internet. That's why I couldn't use the map or anything because I ran it without the WiFi turned on.

If that's the case, how can I use the MapView without using internet connection, when initializing the map itself requires internet connection? Is it actually one of the limitation of the SDK?

THX before

0 Kudos
13 Replies
JasonChristian
Emerging Contributor

The MapOptions is actually still there. But I got everything working now. You just need to check if the internet connection is not available, then add offline features (e.g. tpk files) and it will initialize itself (Don't check for status INIT_SUCCESS). The MapOptions attribute is still useful for when I have slow/unreliable connection, so I don't have to programmatically change the basemap

The solution is to always add any offline features to actually initialize the map when offline (kudos to Alexander)

Thank you for the reply.

0 Kudos
AlexanderNohe1
Honored Contributor

Hey Shelly Gill‌,

I am on Runtime 10.2.8-1.

I went ahead and attempted to do this in a quick sample.

My MapView object looks like this (I dropped all mapOptions attributes):

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

and my mMapView initialization check looks like this:

mMapView = (MapView) findViewById(R.id.map);

mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
    @Override
    public void onStatusChanged(Object o, STATUS status) {
        Log.e("ESS", "STATUS");
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
            loadLayer();
        } else {
            requestStorage();
        }
    }
});

I am not seeing the following:

        Log.e("ESS", "STATUS");

in LogCat, nor is my code running the permission check or the load layer.  I am thinking I might be missing something.  Can you confirm that I might have missed something?

Thanks,

Alexander

0 Kudos
ShellyGill1
Esri Contributor

If the map doesn't have any layers or spatial reference, it won't initialize, so you'd need something to trigger that status changed listener.

AlexanderNohe1
Honored Contributor

Got yah.  Thank you for that information!  This is helpful!

0 Kudos