locked
Is there a way to get sql lite database (*.db3) using another android application? RRS feed

  • Question

  • User397081 posted

    Tried to convert it to stream so I could store it somewhere. But I was unauthorized to do that? Any alternatives?

    var appDirectory = FileSystem.AppDataDirectory; var sourceFile = Path.Combine(appDirectory, "database.db3"); byte[] bytes = File.ReadAllBytes(sourceFile);

    Monday, March 1, 2021 10:32 PM

All replies

  • User369978 posted
    • Make sure the file exists in local folder ,change the file path to System.Environment.SpecialFolder.Personal , it is internal_storage in android , you can check the file existence using File.Exists(dbPath) ;

    • Add the permission in AndroidManifest and perform a runtime permission check , check here .

    Refer to https://forums.xamarin.com/discussion/174032/how-to-read-from-existing-db-file .


    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    Tuesday, March 2, 2021 9:47 AM
  • User397081 posted

    @ColeX Yup, I'm pretty sure that there is a file I was able to access the database from the original app. Maybe I didn't explain myself clearly. My scenario was, I have a two android application the first one is the actual application that we are using and the other one is just a tool that I was using to backup the sqlite database of the first application. I can't access, update and backup the database of the first application that's why I was going to this route. I hope you could help me with this.

    Tuesday, March 2, 2021 11:55 AM
  • User369978 posted

    Sorry, I misunderstood , in this scenario you have to write the file into public external storage in first app , so that the second app could access the file after then .

    The path in code is Android.OS.Environment.ExternalStorageDirectory , and the actual path is /storage/emulated/0/ .

    Refer to https://docs.microsoft.com/en-us/xamarin/android/platform/files/external-storage?tabs=macos#public-external-files.

    Wednesday, March 3, 2021 8:34 AM
  • User397081 posted

    @ColeX thanks, I think that wasn't possible right now since I can't update the deployed application without uninstalling it. With that the sqlite database would be deleted. I found some solution in stackoverflow but not sure yet if it will work.

    https://stackoverflow.com/questions/18471780/retrieve-database-or-any-other-file-from-the-internal-storage-using-run-as/28558521#28558521

    Wednesday, March 3, 2021 6:41 PM
  • User369978 posted

    @projects2016 said: @ColeX thanks, I think that wasn't possible right now since I can't update the deployed application without uninstalling it. With that the sqlite database would be deleted. I found some solution in stackoverflow but not sure yet if it will work.

    https://stackoverflow.com/questions/18471780/retrieve-database-or-any-other-file-from-the-internal-storage-using-run-as/28558521#28558521

    You could have a try and update the result here .

    Thursday, March 4, 2021 6:57 AM