With the Arcgis SDK, Is it possible to store a tile package (.tpk) or a compact cache on the sdcard in a Windows Store App ? - sd-card

I can successfully load a .tkp package in a Windows Store App using the Arcgis SDK when the file is stored in the AppData Folder or the Instal Folder off the App.
Like this :
StorageFile sf = await ApplicationData.Current.LocalFolder.GetFileAsync("Test.tpk");
Layer bkgLayer = new ArcGISLocalTiledLayer(sf);
Map.Layers.Add(bkgLayer);
note : ApplicationData.Current.LocalFolder is the standard local folder :
C:\Users\username\AppData\Local\Packages\app_guid\LocalState
=> The base map is successfully displayed.
But, I have to store the data to the sd card or another folder like My document
So I use :
StorageFile sf= await Windows.Storage.StorageFile.GetFileFromPathAsync(#"C:\Users\<user>\Documents\Test.tpk");
Layer bkgLayer = new ArcGISLocalTiledLayer(sf);
Map.Layers.Add(bkgLayer);
=> The base map is not displayed
In the application manifest, I have access to the documents folder and to .tpk files. I can successfully read and write in this folder using a Stream.
I notice that in the SDK documentation we can read :
ArcGISLocalTiledLayer(StorageItem) : The storage file must be located in a location accessible by the app, ie only local data and app
storage. If the file resides outside these folders, it must be copied
to the local data store first.
So, is it a limitation of the Argis SDK or I made something wrong ?
Is there another way to store a base map outside the AppData folder ?
(The size of the base map is 40Go, and I have to share it between multiple user account)
Thanks a lot for any help :)

Related

What is the difference between getTemporaryDirectory() and getApplicationSupportDirectory()?

What is the main difference between await getTemporaryDirectory();
and await getApplicationSupportDirectory() with Flutter Path provider package.
It is mentioned that what is the underlying calls made for the function:
getTemporaryDirectory , getApplicationSupportDirectory
Considering the example of Android, the path returned by both methods should be used for storing the app-related data.
But there is a minor difference that for the files inside the path returned by getTemporaryDirectory , the system will automatically delete files in this directory as disk space is needed elsewhere on the device. The system will always delete older files first, based on the lastModifiedTime.
Storage permission won't be required for both the methods.
As per documentation :
getTemporaryDirectory :
Path to the temporary directory on the device that is not backed up and is suitable for storing caches of downloaded files.
Files in this directory may be cleared at any time. This does not
return a new temporary directory. Instead, the caller is responsible
for creating (and cleaning up) files or directories within this
directory. This directory is scoped to the calling application.
On iOS, this uses the NSCachesDirectory API.
On Android, this uses the getCacheDir API on the context.
getApplicationSupportDirectory :
Path to a directory where the application may place application
support files.
Use this for files you don’t want exposed to the user. Your app should
not use this directory for user data files.
On iOS, this uses the NSApplicationSupportDirectory API. If this
directory does not exist, it is created automatically.
On Android, this function uses the getFilesDir API on the context.

Store files from flutter application to external storage

Is it always safe to use the path "/storage/emulated/0/{MY APP NAME}" to store the files ?
I Want to store files in the external storage of the android device and I want to store it in a folder named after the app name this folder needs to be located in the external storage.
Have you tried the package path_provider https://pub.dev/packages/path_provider/install?
It comes with the methods getExternalStorageDirectory() and getApplicationDocumentsDirectory() which might be what you are looking for. As far as I know different os types are automatically considered as well.
try the same package of ext_storage named android_external_storage its the same concept putting the downloaded data for example to the download folder.
Check this thread.
The directory an app can access on sdcard looks like /storage/1718-0217/Android/data/com.example.app_name/files. You can get this with the code below.
(await getExternalStorageDirectories())?[1].path;
One app should only access some restricted directories on sdcard. Or you should use Permission.manageExternalStorage.request(), it is strongly restricted and always return false.
Fortunately, per-app directories can also be scanned by other services such like media.

When to use assets in Flutter

What is the best way to use assets in Flutter , for example if i have a file for app configuration , should I store the file by getting the app directory using the path_provider plugin -without using assets- and store it ?, or should I add the file to my program folder -add the file to my assets- ?
the same question if I have a small Sqlite database.
and which of these methods is faster , and which is more secure ?
Assets are files that you add to your app during development. You can load them with rootBundle.load() or rootBundle.loadString() but you cannot modify or delete them.
In the app's directory you can store any files that your app downloads or generates from the internet while running. These files can then be opened, deleted, modified, etc. To access your app directory you need the package path_provider, which tells you the path to your app folder.
A sqlite database is normally stored in the app directory. An example package would be here sqflite.
For speed and security I can't make a difference. An app directory is designed so that only the app can access it. Assets are a part of the app, the application file can theoretically be unpacked by anyone. Therefore I would at least not store secret things in the assets.
Well, if by app configuration you mean the user's settings you can use Sqlite, SharedPreferences or Hive (Hive shows a benchmark that says that it is faster than SharedPreferences).
I believe that assets folder is used to store some common files for the app, like images, icons, fonts, etc. And I think that isn't recommended to store files with some kind of config file, mainly with critical info about the app configuration.

Download offline map at runtime in Flutter using Mapbox?

We have a flutter application where we want to use map functionality in offline mode.
Mapbox provides functionality in the flutter to use offline maps but .db file which contains offline data needs to be saved in the project at build time.
How to achieve the same at runtime?
also open to suggestions to use any other map service providers that works in both online and offline mode.
If you want to store a file on the device please read the official Flutter documentation about Reading and Writing Files
Essentially you need to add path_provider package to your project in order to retrieve the standard cache folder for every device and then simply save you file in it.
This is a my application similar behaviour code
//Get an available temporary dir on device using path_provider package
final Directory tempDir = await getTemporaryDirectory();
//Create a path with file name
final String tempPath = tempDir.path + '/' + 'yourFileName.db';
//Write file on device disk
final File file = File(tempPath);
await writeAsBytesSync(fileContent); //If it is a string use writeAsStringAsync
print('File written on disk');
Then using the file path you can simply read it from disk using readAsByteAsync method.
Remember that in the sample we are using getTemporaryDirectory() and as the documentation tell us
Path to the temporary directory on the device that is not backed up and is suitable for storing caches of downloaded files.
Files in this directory may be cleared at any time.
I would recommend to check out this issue on the github page of the flutter-mapbox-gl repository:
https://github.com/tobrun/flutter-mapbox-gl/issues/88
See the comment of vinceKruger:
https://github.com/tobrun/flutter-mapbox-gl/issues/88#issuecomment-559380534
It is not an official way, but seems to work!

Write to a file in local storage flutter

I know about the path_provider package but it doesn't do what i want, or maybe I'm not just using it right. I read after so many trials and errors that the getApplicationDocumentsDirectory() returns a directory that is accessible only by the app itself, but what if i want to write to a phone's local document directory or so and be able to view the file in my file explorer later on?
If you want to save where the file explorer reaches, you must use the method getExternalStorageDirectory(). It only works in Android and you'll need READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions.
Actually, you're able to find the files saved using getApplicationDocumentsDirectory() and getTemporaryDirectory() as well, but you'd need root access.