Cannot display local .TPK file on Android phone after upgrade to ArcGis Runtime 100.15.4

566
9
02-14-2024 07:11 AM
RobertAnisoiu1
New Contributor II

Hello,

I have an old Android application that display local .tpk file.

I try to rewrite the application using Java and ArcGis Runtime 100.15.4, I have no errors, but the .TPK file is not displayed.

The .TPK file is located in a folder on the phone and the code is below:

public class MainActivity extends AppCompatActivity {
MapView mMapView;
ArcGISTiledLayer localTiledLayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);
 
ArcGISRuntimeEnvironment.setApiKey("API_KEY");
String basemap = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)+"/Folder_Name/MyFile.tpk";

mMapView = (MapView) findViewById(R.id.map);
localTiledLayer = new ArcGISTiledLayer(basemap);

Basemap b = new Basemap();
b.getBaseLayers().add(localTiledLayer);

ArcGISMap arcGISMap = new ArcGISMap(b);

mMapView.setMap(arcGISMap);

}
}

 

and the main.xml file:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<com.esri.arcgisruntime.mapping.view.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

</RelativeLayout>
 
The map from .TPK file is not visible, the only thing that is visible is the ESRI logo on bottom-right of the screen.
 
Can anybody help me with this issue?
Thank you.

 

 

 

 

9 Replies
GuntherHeppner
Esri Contributor

It looks like you are using the wrong constructor to create your ArcGISTiledLayer. In order to create an ArcGISTiledLayer from a tpk file, use the constructor that takes a TileCache, see documention.

0 Kudos
RobertAnisoiu1
New Contributor II

Hello,

Unfortunately it does not work. I tried with TileCache also, but nothing...

What is weird is that if I do not have the .tpk file ib the folder (I deleted for testing), the application does not stop with an error (file not found or something like that...), instead runs and display a blank white screen with ESRI logo in bottom-right corner. So, with or without .tpk file the application run in the same mode.

Below is the source code. Can anybody have any ideea how can I solve this?


public class MainActivity extends AppCompatActivity {

private AppBarConfiguration appBarConfiguration;
private ActivityMainBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

MapView mmapView;
setContentView(R.layout.activity_main);
mmapView=findViewById(R.id.mapView);
// create a basemap from a local tile package
ArcGISRuntimeEnvironment.setApiKey(API_KEY);
String base = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)+
"/myTpkFile.tpk";

TileCache tileCache = new TileCache(base);
ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(tileCache);
ArcGISMap map = new ArcGISMap(new Basemap(tiledLayer));
mmapView.setMap(map);
mmapView.setVisibility(View.VISIBLE);
}

}
0 Kudos
GuntherHeppner
Esri Contributor

To troubleshoot, please check the load status of your TileCache, like this:

TileCache tileCache = new TileCache(base);
tileCache.addDoneLoadingListener {
   Log.d(TAG, ${tileCache.loadStatus})

   if (tileCache.loadStatus == LoadStatus.FAILED_TO_LOAD) {
      Log.d(TAG, ${tileCache.loadError?.message})
   }
}

ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(tileCache);
ArcGISMap map = new ArcGISMap(new Basemap(tiledLayer));
mmapView.setMap(map);


In addition, check out the following sample that uses a tpk file:
https://developers.arcgis.com/android/kotlin/sample-code/offline-routing/

0 Kudos
RobertAnisoiu1
New Contributor II

Hello Gunther,

thank you very much!

I did the check and the .tpk file is not loaded, that's why I have a white balnk screen with or without the .tpk in location.

 

What can I do now? I need to provide read rights in the manifest file?

Thank you for helping me,

Regards,

Robert

0 Kudos
GuntherHeppner
Esri Contributor

What exactly is the load error you get back from tileCache.loadError?

What can I do now? I need to provide read rights in the manifest file?

If your tpk file is located in shared storage, yes, you need to specify READ_EXTERNAL_STORAGE permission. Please refer to the Android documentation for details on storage.

0 Kudos
RobertAnisoiu1
New Contributor II

The load error is: "com.esri.arcgisruntime.ArcGisRuntime Exception: File not found.:Package file not found"

I cannot use READ EXTERNAL STORAGE permission because I have Android 14 and this permission is deprecated and I don't know where I need to copy the .tpk files on the phone, in order to be found by application.

The application package name is com.example.reteaanp

0 Kudos
GuntherHeppner
Esri Contributor

It depends on you application requirements where you need to deploy your tpk file. If you can deploy it on app specific external storage or internal storage, you won't need to request any permissions to read the file. You can then use APIs like `getExternalFilesDir`: https://developer.android.com/training/data-storage/app-specific
More details on storing media files on app sepcific storage here: https://developer.android.com/training/data-storage/app-specific#media

If your tpk needs to be deployed on shared storage, you may need to request permissions to access all files:
https://developer.android.com/training/data-storage/manage-all-files

0 Kudos
RobertAnisoiu1
New Contributor II

I don't need to deploy anywhere the .tpk files. I have the .tpk files, made with ArcGis Desktop v10.1. I must copy the .tpk files on the phone somewhere where these files can be found by the application and loaded into a TileCache and after that in a map that is displayed on the phone.

In the older version it was no problem. The .tpk files were in a folder in the phone and the application ran for many years without any problem.

Now I have difficulties because I tried to store the .tpk files into DCIM folder but the TileCache run into the error that "the file is not found".

0 Kudos
RobertAnisoiu1
New Contributor II

The problem was solved, thank you Gunter! It was a permissions issue.

0 Kudos