question

SethIsaacks-9226 avatar image
0 Votes"
SethIsaacks-9226 asked LeonLu-MSFT commented

Xamarin backup sqlite to external storage

Hello, I am wondering if someone can help me. I have an Xamarin Flyout App. I have a local sqlite db that I want to backup to external storage and restore from in the event that say the data on the app has to be cleared. I have googled and googled and googled but I cannot find an answer as to how to accomplish this task. Any help would be much appreciated.

dotnet-xamarindotnet-sqlite
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT commented

Hello,​

If Apps that run on Android 11 but Target Framework set to Android 10 (API level 29), you can set the android:requestLegacyExternalStorage="true" attribute in <application> tag.

If Target Framework set to Android 11, Starting in Android 11, apps cannot create their own app-specific directory on external storage without grand any permission. You can refer to this storage doc in android 11.

You can try to upload your SQLite DB to Azure Storage and you can download it when you need to use, Azure Storage is a scalable cloud storage solution that can be used to store unstructured, and structured data.

If you have to request All files access, you can declare the MANAGE_EXTERNAL_STORAGE permission in the manifest and request this permission. For more details, please refer to Manage all files on a storage device

Best Regards,

Leon Lu



If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


MAUI is currently in Preview and not yet supported on Microsoft Q&A. Please post any MAUI questions or feedback in the MAUI repository at https://github.com/dotnet/maui



· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@LeonLu-MSFT I am currently targeting Android 12. I plan to create a backend in the near feature with Azure. Its quite a process to get all that done. Its in our next milestone. For now we are just wanting to create a backup of the data in the event for some reason the user has to clear the app data....for example if the app starts crashing for unexpected reasons. I did an update not long ago and on some Android phones the app would simply crash. On other Android phones the app worked just fine. After much googling, I found that the common theme on Android was to delete the App data. Sure enough, it worked. However that hoses the database and the user looses all their data. Hints why I am looking to put a backup somewhere.

0 Votes 0 ·
LeonLu-MSFT avatar image LeonLu-MSFT SethIsaacks-9226 ·

If common theme on Android was to delete the App data, I think you can try to cloud Realtime database(Azure Cosmos DB) directly. Store your data to cloud.

0 Votes 0 ·

@LeonLu-MSFT My apologies, I phrased that wrong. When Googling, the most common answer I found, when apps are crashing on a certain phones and not others, was to delete the app data. I still have no clue as to why on 3 Android phones out of 25, why I was forced to delete the App data. The app I am designing will be used "off line" or "out of service area" more often than not. So a real time database is not going to work....which is why I am trying to figure out a way to copy a .db3 file to external storage. This time next year I will have the backend up and running that can be used for syncing when service is available. The backup will be in the event they are offline or out of service and something happens.

I tried writing a file to emulated storage but when app data is deleted those files are as well. It appears I cannot write a file to any location that will not be deleted when app data is cleared.
I looked into Firebase but...one of the "gotchas" is if you are not logged in to the app before you lose service, then you cannot log in. As I said, most of our users will be offline most of the time.

So as of now I am unsure of how to backup a sqlite database to a location where it would not be deleted. The only option I know of is going down the path of creating a backend for syncing with service is available.

I tired to find information for uploading and dowloading a file from google drive. But I found very little information on that. There was a nuget package but has since been discontinued.

Do you have any suggestions?

0 Votes 0 ·
Show more comments